I want to get the point, where my mouse is pointing in wold space. But i get this error:
NullReferenceException
UnityEngine.Camera.ScreenPointToRay (Vector3 position)
this is my script:
function Update ()
{
var hit : RaycastHit;
var ray : Ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, hit, Mathf.Infinity))
{
Debug.Log(hit.point);
}
}
The Console says the error is in this line:
var ray : Ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
… i dont know what is false?! Can someone help me?
Set "mainCamera" to "main": Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
– NemGamingAkos