Hello everybody.
I am trying to use a raycast to get the world position of a game object with the following script, attached to my main camera :
#pragma strict
private var hitPos : Vector3 ;
private var hitObjectPos : Vector3 ;
function Update(){
if (Input.GetMouseButtonDown(0))
{
Debug.Log("Pressed left click.");
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition) ;
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100))
{
Debug.Log("Physics Raycast ok.");
Debug.DrawLine (ray.origin, hit.point);
hitPos = hit.point ;
hitObjectPos = hit.transform.position ;
Debug.Log("World position : "+hitObjectPos);
}
}
}
The message “Pressed left click.” is correctly printed on the console, but not the following messages. Notice that I have added a collider to my game object :
Have you an idea of what I have forgotten or done wrong ?
Thank you for reading.
