- Home /
This question was
closed May 07, 2018 at 08:14 AM by
Myth for the following reason:
The question is answered, right answer was accepted
Question by
Myth · Apr 10, 2011 at 05:24 AM ·
raycastsendmessage
Raycast message problem
Hi,
Why is this spitting a null reference at me?
Any help is greatly appreciated!
var team : String = "blue";
function Update () { var hit : RaycastHit;
if (Physics.Raycast (transform.position, Vector3.forward, 2))
{
hit.collider.SendMessage("Capture", team, SendMessageOptions.DontRequireReceiver);
}
}
Comment
Best Answer
Answer by KeithK · Apr 10, 2011 at 07:28 AM
You need to pass your "hit" variable into Physics.Raycast(), it's inside that function that it gets assigned. At the moment you declare it, where it starts off as null and leave it like that.
Try this:
Physics.Raycast (transform.position, Vector3.forward, hit, 2)