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

script

Discussion in 'Scripting' started by ahmedalheday, May 11, 2014.

  1. ahmedalheday

    ahmedalheday

    Joined:
    Feb 24, 2014
    Posts:
    103
    The animation state Attack could not be played because it couldn't be found!
    Please attach an animation clip with the name 'Attack' or call this function only for existing animations.
    UnityEngine.Animation:play(String)
    Meleesystem:Update() (at Assets/scrpits/Meleesystem.js:12)

    i did it but it does not work
     
  2. Findo

    Findo

    Joined:
    Mar 11, 2014
    Posts:
    368
    We have no idea how to fix it because ur not posting your code.
     
  3. Slaghton

    Slaghton

    Joined:
    Sep 9, 2013
    Posts:
    139
    On your player, the animation component, did you go to say element 0 and select the animation clip? This is the error you get if you don't.
     
  4. ahmedalheday

    ahmedalheday

    Joined:
    Feb 24, 2014
    Posts:
    103
    #pragma strict

    var TheDammage : int = 50;
    var Distance : float;
    var MaxDistance : float = 50;
    var TheMace : Transform;

    function Update ()
    {
    if (Input.GetButtonDown("Fire1"))
    {
    //Attack animation
    TheMace.animation.Play("Attack");
    //Attack function
    var hit : RaycastHit;
    if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
    {
    Distance = hit.distance;
    if (Distance < MaxDistance)
    {
    hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
    }
    }
    }
    }
     
  5. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,952
    You need to have an animation attached to TheMace, and it has to have a anim called "Attack", just like the error says.
     
  6. ahmedalheday

    ahmedalheday

    Joined:
    Feb 24, 2014
    Posts:
    103
    i did
    but it does not work :(
    it shows me the same error
     
  7. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
  8. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,952
    Then you didn't do it correctly, it is one (or more) of three things:
    1. "TheMace" is not linked to that script in the inspector
    2. "TheMace" does not have an animation attached to it.
    3. The animation on "TheMace" does not have an animation called "Attack"

    When all 3 of those things are checked and fixed, it will work.