So I want a script that when a specific object is touched, (the clone) it is pushed along the Z axis. Unfortunately, I can’t get it to recognize a specific object and then give it velocity.
here is my script so far, doesn’t work, besides casting a ray from touch position and detecting the object touched:
private var hit : RaycastHit;
private var ray : Ray;//ray we create when we touch the screen
function FixedUpdate () {
if(iPhoneInput.touchCount == 1) {
ray = Camera.main.ScreenPointToRay(iPhoneInput.touches[0].position);
Debug.DrawLine(ray.origin,ray.direction * 10);
if(Physics.Raycast(ray.origin, ray.direction * 10,hit)){
Debug.Log(hit.transform.name);//Object you touched
//So right here is my problem, I need to find out which object was touched, and if its a clone of the ball (or any object I want), then it is pushed along the Z axis.
if(hit.transform.tag == "clone"){
clone.velocity = transform.TransformDirection (Vector3.forward * 10);
Debug.Log("By God, IT WORKED!");
}
}
}
}