Search Unity

Trouble changing my animation state

Discussion in 'Animation' started by jsull1, Apr 29, 2018.

  1. jsull1

    jsull1

    Joined:
    Apr 3, 2018
    Posts:
    121
    My script was working perfectly but my animation controller disappeared, I made a new one but for some reason the script is no longer changing my animation state. This is my script;
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class AnimScript : MonoBehaviour {
    6.  
    7.     private Animator anim;
    8.  
    9.     void Start () {
    10.  
    11.         anim = GetComponent <Animator> ();
    12.        
    13.     }
    14.    
    15.  
    16.     void Update () {
    17.  
    18.         if (Input.GetKeyDown ("up")) {
    19.             anim.SetInteger ("State", 1);
    20.         }
    21.         if (Input.GetKeyUp ("up")) {
    22.             anim.SetInteger ("State", 0);
    23.         }
    24.     }
    25. }
    26.  
    My animation controller is called Animations but I don't think that should matter, what am I doing wrong??
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,435
    Which component you are using?

    Animation
    upload_2018-4-30_14-40-38.png

    or Animator
    upload_2018-4-30_14-40-55.png
     
  3. jsull1

    jsull1

    Joined:
    Apr 3, 2018
    Posts:
    121
    I'm using Animator
     
  4. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Does it need to have the Avatar assigned in the component? Looks like it's not in that screenshot. Check that maybe?
     
  5. jsull1

    jsull1

    Joined:
    Apr 3, 2018
    Posts:
    121
    That wasn't my screenshot above, that was someone's example this is what I'm working with:
    Screen Shot 2018-04-30 at 4.28.44 PM.png
    I didn't need an avatar before, this issue is that my script is not accessing my state variable inside the animator and I'm not sure why.
     
  6. jsull1

    jsull1

    Joined:
    Apr 3, 2018
    Posts:
    121
    I've tried deleting the animation component and that didn't help it, I have no idea why the variable is not being accessed
     
  7. jsull1

    jsull1

    Joined:
    Apr 3, 2018
    Posts:
    121
    I GOT IT! The answer wasn't in the question so you guys couldn't have figured it out but I really appreciate the effort. My issue was that "State" in the animator was actually a float value, not an integer, and so it was not changing the value. I really appreciate the help though, you guys are awesome!
     
  8. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,824
    Hehe, glad you got there! That has got me before too :oops: