Search Unity

I don't understand how Animation.Play works

Discussion in 'Animation' started by mike1377, May 23, 2015.

  1. mike1377

    mike1377

    Joined:
    May 6, 2015
    Posts:
    16
    I've seen the Animation Scripting Tutorial in the beginner series, read a bunch of questions, and seen the doc (the doc I can't make sense of, cuz I don't understand how to tell the difference between the required non-changing parts and the variables)

    it's a simple code, on an imported GameObject, just a simple Cube. there's no avatar, no skeletal system. It just scales and moves, i'm using it to understand how to animate. there's two animations, one which is called Idle, the default state, where almost nothing happens. the other is called Take1 in the Animator, and "moveffs" in the actual Asset folder. both were made using Unity's built-in Animation Window.

    the basic idea is to have it barely visible, then scale when a certain button is pressed.

    My current code (which i've changed easily over 50 times and probably will have changed before there's a reply)




    int jumphash = Animator.StringToHash ("Take1");
    // Use this for initialization
    void Start () {
    Anim = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update () {


    if (Input.GetButton ("fire3")){
    anim.SetTrigger (jumphash);

    }
    }
    }


    current error:

    Assets/beam/F***ingplayBeam.cs(10,17): error CS0103: The name `Anim' does not exist in the current context
     
    Last edited: May 23, 2015
  2. mike1377

    mike1377

    Joined:
    May 6, 2015
    Posts:
    16
    As a side-note, did anyone notice the Grammar error in the Questions section where, as a new user, "
    The question is waiting approval by a moderator."? There should be the word "for" after "waiting."

    It doesn't really bug me, I just thought I'd point it out in case the company would care.
     
    Last edited: May 23, 2015
  3. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Yeah I noticed that - it doesn't really bug me either. It could also be awaiting approval by a moderator.
    I also notice people use cuz in place of the word because. o_O It bugs some people.

    You may want to check out some additional animation tutorials in the learn section, 2D in particular. I think you'll find what your looking for if you dig around a little bit more.
    Also - I'm not a coder so it's not my thing, but others around here request you use the code tag for code to help them help you.
    Code (CSharp):
    1. I'm under the insert button - code
     
  4. CodeMonke234

    CodeMonke234

    Joined:
    Oct 13, 2010
    Posts:
    181
    You need to declare a variable in your class before using it.
    Animator Anim;