- Home /
trigger animation
i want to play an animation once the player hits a collider. i tried using this: if(collider.tag == "anim_trigger1") { this.transform.GetComponent(Animation).animation.Play ("enemy"); }
where "anim_trigger1" is the tag of the collider and "enemy" is the name of the animation applied on another object. And i'm getting the following error: "*Assets/script/player_control. j s(38,72): B C E 0 144: 'Unity Engine .Component.animation' is obsolete. Property animation has been deprecated. Use Get Component() instead. "...
thanks in advance
Answer by dev-waqas · Jan 23, 2018 at 02:01 PM
The problem is accessing .animation
again and also in a wrong way. You don't need to write it you can simply play animation using code like this.
this.GetComponent<Animation>().Play ("enemy");
Answer by unity_6rohit8 · Jan 23, 2018 at 02:05 PM
i tried as you suggested , but i got these following three errors:
Assets/script/player_control.js(38,62): BCE0043: Unexpected token: ). Assets/script/player_control.js(38,63): BCE0044: expecting ), found '.'. Assets/script/player_control.js(38,64): UCE0001: ';' expected. Insert a semicolon at the end.
no.. actually i'm getting this error:
$$anonymous$$issingComponentException: There is no 'Animation' attached to the "player" game object, but a script is trying to access it. You probably need to add a Animation to the game object "player". Or your script needs to check if the component is attached before using it. UnityEngine.Animation.Play (System.String animation) (at C:/buildslave/unity/build/artifacts/generated/common/modules/Animation/AnimationsBindings.gen.cs:428) player_control.OnTriggerEnter (UnityEngine.Collider collider) (at Assets/script/player_control.js:38)
Are you sure you have an Animation Component on your player? If yes, maybe you're using the Animator component ins$$anonymous$$d of the Animation component? They are different things, but the name is really similar