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

setting ai animation?

Discussion in 'Scripting' started by simplicitygs, Jul 26, 2014.

  1. simplicitygs

    simplicitygs

    Joined:
    May 14, 2014
    Posts:
    9
    How would you go about setting the animation of an ai? For example, running, idle etc. animation.Player(); does not seem to work for me?
     
  2. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    Assuming you're using legacy,

    You'll need to access the animation component and then type:

    animation.Play("animation name");
     
  3. Sykoo

    Sykoo

    Joined:
    Jul 25, 2014
    Posts:
    1,394
    Do you only need animation playing part of the script or also AI movement?

    Code (JavaScript):
    1. function Update(){
    2.        animation.Play("AnimationName");
    3. }
     
  4. Zackhanzo

    Zackhanzo

    Joined:
    Jun 5, 2014
    Posts:
    65
    And if you are using mecanim just use variable of the type Animator, get the components of Animator on the script. And then just

    nameOfAnimatorValue.SetBool/Float...("nameOfTheVariableOnTheAnimator",true(bool)/false(bool) or floatnumber(float))

    something like this.

    animator.SetBool("Shoot",true); animador.SetBool("Shoot",false);
     
  5. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008

    Don't do it this way.

    This is performance heavy.

    You can do it through start.

    void Start()
    {
    animaion["CLIPNAME"].wrapmode = WrapMode.loop;
    animation.play("ClipNAME");
    }