Search Unity

OnCollisionEnter trigger animation

Discussion in 'Scripting' started by RHD, Aug 24, 2016.

  1. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    I can't understand why this isn't working.
    I've been going through all the threads on here and Unity Answers and I'm still missing something.
    This is a script directly copied from Unity's Scripting reference.

    The script is attached to the moving object, everything has colliders which are working because the moving object bounces off but the animation doesn't trigger.

    I just want the moving object to have one animation while it's moving and then another after it hits something.
    Thank you.

    function onCollisionEnter(col : Collision)
    {
    if(col.gameObject.name == "Bat_Death")
    {
    animation.Play("Death", PlayMode.StopAll);
    //audio.PlayOneShot(AudioClip);
    }
    }
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    OnCollisionEnter
     
  3. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    Thank you!

    That was a stupid mistake!
     
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
  5. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    Thank you, don't suppose you've got a link for how to get the animation to play once and stop?
     
  6. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    Ah ha!:

    animation.wrapMode = WrapMode.Once;
     
    LeftyRighty likes this.