Hi. I’ve created a simple script to universally trigger the “Action” function in any gameobject. For example, if I wanted to open a door by pressing “E” while looking at it, I would attach an “Open” script to the door with the function “Action.” However, I am receiving null results. Take a look.
The SendAction script:
#pragma strict
var RaycastDist : float = 5;
var action = 1;
function Update () {
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
var hit : RaycastHit;
if(Input.GetKeyDown(KeyCode.E)) {
if(Physics.Raycast (ray , hit, RaycastDist)){
hit.collider.SendMessage("Action", action, SendMessageOptions.DontRequireReceiver);
}
}
}
The SelfDestruct script:
#pragma strict
var Cube : GameObject;
function Action(){
Cube.transform.active = false;
}
Please tell me what is going wrong.