Search Unity

Anim.SetBool isn't setting anything to anything

Discussion in 'Scripting' started by abstractfragment, May 28, 2014.

  1. abstractfragment

    abstractfragment

    Joined:
    Jan 16, 2014
    Posts:
    15
    So I'm having this issue where Unity's animator isn't realizing we changed direction when the actual code realizes it. I want to be able to have different animations for each direction.

    Relevent image explaining the problem.

    $facingreft.jpg

    Relevent coding bits are below. I'm not exactly sure what's going on.

    Code (csharp):
    1.     Animator anim;
    2.      
    3.     public LayerMask whatIsGround;
    4.     public Transform groundCheck;
    5.     public bool facingright = true;
    6.  
    7.  
    8.     // Use this for initialization
    9.  
    10.     void Start ()
    11.     {
    12.  
    13.         anim = GetComponent<Animator> ();
    14.         anim.SetBool ("isFacingRight", facingright);
    15.         }
    Code (csharp):
    1. void flip ()
    2.     {
    3.         facingright = !facingright;
    4.         Vector3 theScale = transform.localScale;
    5.         theScale.x *= -1;
    6.         transform.localScale = theScale;
    7.     }
     
  2. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    You would have to call anim.SetBool in flip. You only do it in Start.
    You are only passing a new value, not any kind of persistant reference.
     
    Last edited: May 28, 2014
  3. abstractfragment

    abstractfragment

    Joined:
    Jan 16, 2014
    Posts:
    15
    Okay I see. I thought Anim.SetBool would set the Bool to the Animator Bool but I see now it only does that when you call it. Thanks man! Would it work better if it was in FixedUpdate? That way it's always checking.