- Home /
Question by
$$anonymous$$ · Mar 26, 2013 at 10:16 AM ·
raycastnullreferenceexception
Problem with Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
I want to get the point, where my mouse is pointing in wold space. But i get this error:
UnityEngine.Camera.ScreenPointToRay (Vector3 position) this is my script: function Update () { var hit : RaycastHit; var ray : Ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);NullReferenceException
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?
Comment
Best Answer
Answer by whydoidoit · Mar 26, 2013 at 10:17 AM
I'm guessing that none of your cameras is tagged as "MainCamera"
screen shot 2013-03-26 at 10.22.41.png
(13.4 kB)
Your answer
Follow this Question
Related Questions
RaycastHit2D.collider is null - why? 1 Answer
Why am i getting a null reference exception? 1 Answer
Picking Weapons Up with Raycast 1 Answer
NullRefException in RaycastAll 2 Answers
Null reference exception help 0 Answers