Hi, I have added animation to a door and when I hit it, it will play the animation…problem is that it plays animation every time I hit the door…How can I make my animation play only 1 time when I hit the door???
MY script is:
function OnControllerColliderHit
(hit : ControllerColliderHit)
{ if(hit.gameObject.tag == “door”)
{ hit.gameObject.animation.Play(“door”);
}
You can make a boolean to control that. Make the animation play only if the boolean is false. When the boolean is true, don’t play the animation.
i.e
var isPlayed : boolean = false; function OnControllerColliderHit (hit : ControllerColliderHit) { if(hit.gameObject.tag == "door") { if (!isPlayed) { hit.gameObject.animation.Play("door"); isPlayed = true; } } }
Cheers! ^^