Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

mecanim animations work with one script but can't be found with another....please help

Discussion in 'Animation' started by matthew77, Oct 1, 2017.

  1. matthew77

    matthew77

    Joined:
    Dec 17, 2016
    Posts:
    29
    I have one script that triggers mecanim animations on the player by pressing keys. This works fine. When I try to do a script to trigger the animations with a collider trigger I get an error that the animation couldn't play because it couldn't be found.

    Can anyone help me to figure out why it can find the animation and apply it with the keyboard trigger method but not the collider trigger method?

    I'm totally lost and have been looking for a solution for weeks in the forums and on Unity Answers and YouTube with no success.

    Please help.
     
  2. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    Post your code if you need the help.
     
  3. matthew77

    matthew77

    Joined:
    Dec 17, 2016
    Posts:
    29
    thanks for the response. This is the code:

    Code (csharp):
    1.    
    2.  
    3. #pragma strict
    4.  
    5. function OnTriggerEnter (collision : Collider) {
    6.  
    7. if (collision.gameObject.tag == "Player"){
    8.  
    9. collision.gameObject.GetComponent.<Animation>().Play("bench sit new");
    10. }
    11. }
    12.  
    It seems to want to work but for the fact that it states it can't find the animation. It finds it on keyboard press though.
     
  4. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    Without seeing the other code that works, I can only tell you possible issues.

    1 make sure that the gameobject with the tag “Player” has the Animation component. It can’t be a parent or child.

    2. Make sure that there are not other gameobjects (even children) that have the Player tag AND don’t have an animation component...that will cause the code to fail.