Hello everyone, so i’m having trouble getting my animator to switch states from walking (Normal State) to idle (Default state). I’m using a parameter called “isWalking”(boolean) that is set to false and it is supposed to switch to true when the player moves and switches back to false when the player stops moving. When “isWalking” is true, the walking animation will go though its cycle. The player doesn’t animate when the “a” key is pressed. I have been working at this for an hour and I still can’t get it to work problem.
The code is attached to this post
I hope someone can help me with this issue or if you need more info I’ll be glad to give it you.
Thanks, Joseph
2464739–169618–PlayerController.cs (1.31 KB)
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float moveSpeed;
public float jumpHeight;
public Transform groundCheck;
public float groundCheckRadius;
public LayerMask whatIsGround;
private bool grounded;
private bool doubleJump;
private Animator anim;
// Use this for initialization
void Start ()
{
anim = GetComponent ();
}
// Update is called once per frame
void Update ()
{
if (grounded)
doubleJump = false;
if (Input.GetKeyDown (KeyCode.Space) && grounded)
{
Jump();
}
if (Input.GetKeyDown (KeyCode.Space) && !doubleJump && !grounded)
{
Jump();
doubleJump = true;
}
if (Input.GetKey (KeyCode.A))
{
GetComponent ().velocity = new Vector2 (-moveSpeed, GetComponent().velocity.y);
anim.SetBool (“IsWalking”, true);
}
if (Input.GetKey (KeyCode.D)) {
GetComponent ().velocity = new Vector2 (moveSpeed, GetComponent ().velocity.y);
anim.SetBool (“IsWalking”, true);
}
else
anim.SetBool (“IsWalking”, false);
}
void FixedUpdate()
{
grounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);
}
public void Jump()
{
GetComponent ().velocity = new Vector2 (0, jumpHeight);
}
}