Tuesday, June 28, 2011

how to make a animation play only when I get into the range of that game object?

 i have a game object that is an enemy. I want its animation to play only when I get really close to it.(im controllled by a fps player controller in my game) 



var rayCastLength = 5;
function Update () { var hit : RaycastHit;
//check if were in range... 
if(
Physics.Raycast(transform.position, transform.forward, hit, rayCastLength))
 { // ... 
with the object if(hit.collider.gameObject.tag == "lift_door") 
{
 //play the animation: hit.collider.gameObject.animation.Play("lift_door_open"); 
}



}

No comments:

Post a Comment