How do I play a animationclip if a object with the tag “Target” gets in a trigger tagged “Bullet”
I think the script will be like this but I’m not sure:
public var DeathAnimation : AnimationClip;
public var DeathAnimationSpeed : float = 1.15;
fucntion OnTriggerEnter(collider : Collider)
{
if(collider.tag == "Target")
animation.Play()
}
The Animation Clip has to be set on the Animation component in the editor.
(or by script, but editor is simpler)
Then you can play it by name.
P.S. Naked ifs will work, but are very bad programming practice and will bite you later. You should ALWAYS uses {} even if the body is only 1 line.
void Start(){
animation.AddClip(deathClip,"Death");
}
void OnTriggerEnter(Collider other) {
if (other.gameObject.tag=="Bullet"){
animation.Play("Death");
}
}