Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How To Use The Animator Parameters In My Script?

Discussion in 'Animation' started by infamouslyuseless, Dec 5, 2013.

  1. infamouslyuseless

    infamouslyuseless

    Joined:
    Oct 30, 2013
    Posts:
    19
    I get the animator with the parameters and everything, and i can turn things true or false, but i'm not sure how to use them in my script (javascript). I have let's say a boolean called Attack that turns to true when you click 'Fire1'. I can use it and it works when i manually turn it on in the animator, but how do i make it so that when you left click it makes Attack true, which then plays the attack animation. Thanks
     
  2. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    699
    In your script, you would use Animator.SetBool to set that boolean, just as if it had been turned on in the animator editor.
    So, something like-
    Code (csharp):
    1.  
    2. Animator animator = GetComponent<Animator>();
    3. if (Input.GetButton ("Fire1")){
    4.    animator.SetBool("nameofbool", true);
    5. }
    6. else animator.SetBool("nameofbool", false);
    7.  
     
  3. infamouslyuseless

    infamouslyuseless

    Joined:
    Oct 30, 2013
    Posts:
    19
    I did that with the right booleans, this was the code


    Code (csharp):
    1. Animator animator = GetComponent<Animator>();
    2.    
    3.     if (Input.GetButtonDown("Fire1"))
    4.     {
    5.         //Attack
    6.         animator.SetBool("Attack", true);
    but i get these errors: ';' expected. insert semicolon at the end

    'unexpected token: )

    expecting ), found ';'



    they're all for the same line, the Animator animator = GetComponent<Animator>();

    why does this happen?