- Home /
how to animate on trigger?
how can I animate my player when it passes a trigger?
Comment
Best Answer
Answer by gianni123 · May 22, 2010 at 10:18 AM
this WORK! find on unity forum:
var animateobject: GameObject;
function OnTriggerEnter (collision : Collider)
{
if (collision.gameObject.tag == "Player") //
{
animateobject.animation.CrossFade ("animationname");
} }
Answer by Mike 3 · May 21, 2010 at 03:24 PM
function OnTriggerEnter(hit : Collider)
{
if(hit.gameObject.name == "Player") // this bit probably needs changing to suit your game
{
hit.gameObject.animation.Play(); //change this to Play("animation name") if you like
}
}
even if I use it without changing the name of the animation, simply does not work ..
Your watertouch parameter should be "watertouch" (a string), the string name of the animation you want to play. Insure that your animation clip that you wish to play is named the same.
as you see in the screenshot, the animation "watertouch" is attached to "messoplayer"