- Home /
How to Play an animation state on an animator controller on collision?
I'm able to do it with legacy animations using this code -
private var hasPlayed = false;
var other : GameObject;
function OnTriggerEnter(){
if(!hasPlayed){
other.GetComponent.<Animation>().Play();;
hasPlayed = true;
}
}
How would I edit this to use the animator instead of legacy.
I've looked around and can't seem to find an answer. Any help would be appreciated.
Comment
Answer by Archimagus · Apr 03, 2015 at 06:56 PM
private var hasPlayed = false;
var other : GameObject;
function OnTriggerEnter(){
if(!hasPlayed){
other.GetComponent.<Animator>().SetTrigger("TriggerForStateToPlay");
hasPlayed = true;
}
}