I’m trying to send a short distance raycast in order to activate in-game, things such as doors and buttons. I’ve been trying to get this to work for a couple days but I’ve found no luck. I can’t seem to find anything wrong with my script. I’ve done much debugging and have found out that the raycast is simply not initiating. Look over my script and tell me what is going on.
#pragma strict
var RaycastDist : float = 5;
var action = 1;
function Update() {
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width / 2, Screen.height / 2, 0));
var hit : RaycastHit;
var fwd = transform.TransformDirection (Vector3.forward);
if(Input.GetKeyDown(KeyCode.E)) {
if(Physics.Raycast (ray, hit)){
hit.collider.SendMessage("Action", action, SendMessageOptions.DontRequireReceiver);
}
}
}