Log in or register to post comments

Can't make object fall over time on touch

June 5, 2015 - 4:55pm #1

Hey guys, I've been trying to figure out how to make an object fall when hit by a raycast. I've been working in C-Sharp. I'm at the end of my rope and have no ideas left. If you have any Idea of how to execute this, please let me know!

Thank you in advance!

Here is my code:

<pre class="brush: csharp">

using UnityEngine;
using System.Collections;
 
public class touch2 : MonoBehaviour {
public Transform Particle_System;
public GameObject Tower;
public GameObject Poof;
public float speed = 10;
 
 
private Ray ray; // cast array
public RaycastHit rayHitInfo = new RaycastHit(); // object that was hit by array
// Update is called once per frame
void Update () {
 
 
 
if (Input.touches.Length <= 0) 
{
//if no touch recognised then there will be no interaction
}
else
{
for (int i = 0; i < Input.touchCount; i++)
{
if(Input.GetTouch(i).phase == TouchPhase.Began)
{
ray = Camera.main.ScreenPointToRay (Input.GetTouch(i).position);
if(Physics.Raycast(ray, out rayHitInfo)) 
{
 
 
rayHitInfo.transform.gameObject.transform.Translate(Vector3.down * speed * Time.deltaTime);
 
 
 
}
}
}
 
 
 
}
}
}
 
</pre>
Log in or register to post comments