I want to move an object when it has been touched. So I am using the below code to ray cast and calling the Move method on the touched object. This code is working fine when camera is near to the object but if the camera is far (not very far ) from the object ray cast is not working. What is the problem? Plz any one help me I am waiting here for reply…
function Update () {
if(Input.touchCount > 0){
Debug.Log("Ray casting"+ Input.GetTouch(0).deltaPosition);
var ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).deltaPosition);
var hit: RaycastHit;
if (Physics.Raycast (ray,hit, 100000)) {
Debug.Log("Ray casted");
hit.transform.gameObject.SendMessage("Move");
}else{
Debug.Log("Ray not casted");
}
}
}