- Home /
Object reference not working
Here is my code that was working yesterday and now doesn't work. I get an 0bject reference not set to the instance of an object error, but I'm sure it has the tag and everything? Any help?
private var ray: Ray;
private var rayCastHit: RaycastHit;
function Update(){
if(Input.GetMouseButton(0)){
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(rayCastHit.collider.gameObject.tag == "playbutton"){
Application.LoadLevel ("maingame");
}
}}
At what line is this error ? And it looks like your rayCastHit object is not initialized: don't you miss a physics.raycast() call somewhere ?
@dns a RaycastHit does not need to be initialized up front. It is a struct and will get it value from the Raycast(), but he is missing the Raycast() call. Without the Raycast(), rayCastHit is uninitialized on line 11 when it is being used.
Your answer
Follow this Question
Related Questions
NullReferenceException:"Object reference not set to an instance object" 1 Answer
Object reference not set to an instance of an object 1 Answer
Object Refererence not set yada yada... 2 Answers
NullReferenceException was thrown. Object reference not set to an instance of an object. 1 Answer
Object reference not set to an instance of an object. 0 Answers