Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

An error in calling animation with script.

Discussion in 'Scripting' started by cristo, Nov 16, 2014.

  1. cristo

    cristo

    Joined:
    Dec 31, 2013
    Posts:
    265
    Hi, I'm just trying to trigger a simple walk animation in my enemy AI script when the player approaches the enemy, and I'm just wondering why an error's coming up. I understand the animation clip is attached.
    The following is part of the code attached to the enemy.

    if (playerDistance <15f)
    {
    enemyAnimation();
    }

    void enemyAnimation ()
    {
    animation.Play("Take001");
    } animationnn.jpg
     
  2. Nubz

    Nubz

    Joined:
    Sep 22, 2012
    Posts:
    553
    Code (CSharp):
    1. void enemyAnimation ()
    2. {
    3. animation.Play("Take001");
    4. }
    And in the inspector it says "Take 001"
     
  3. cristo

    cristo

    Joined:
    Dec 31, 2013
    Posts:
    265
    Thanks Nubz, that's such a simple and stupid mistake of mine.
     
  4. Nubz

    Nubz

    Joined:
    Sep 22, 2012
    Posts:
    553
    I've been there before too many times to count hahaha.
    No problem.
     
    cristo likes this.