Hi I need to know how to activate a script at runtime on a raycast collision heres the scripts im using now, the function update one is the one im using to find the gameobject and then find the script and then activate it on a raycast hit this one is called ZombieAIRaycast… And the one im trying to activate is the MoveForward script at the bottom. The move forward script is attached to my AI(ZombieCharacter) and the ZombieAIRaycast script is on my FirstPersonController(and no I did not get these mixed up) Please Help. The code I used is in Java.
function Update ()
{
var forward = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
Debug.DrawRay(transform.position, forward * 5, Color.blue);
if(Physics.Raycast(transform.position, forward, hit, 5))
{
if(hit.collider.gameObject.name == "top")
{
if(gameObject.Find("ZombieNormalDragLeg") != null)
{
Debug.Log("ZombieNromalDragLeg object found...");
gameObject.Find("ZombieNormalDragLeg").SendMessage("MoveForward");
}
}
}
}
Move Forward script
var speed : float = 5.0;
function Update () {
transform.Translate(Vector3(0,0,speed) * Time.deltaTime);
}
[Edit by Berenger, code formatting]