I am trying to animate a walk and the animator will not switch states. Here are my scripts
// Enemy_Skeleton (attached to parent object of animator)
public class Enemy_Skeleton : Enemy
{
#region States
public SkeletonIdleState chillState { get; private set; }
public SkeletonMoveState walkState { get; private set; }
#endregion
protected override void Awake()
{
base.Awake();
chillState = new SkeletonIdleState(this, stateMachine, "Chill", this);
walkState = new SkeletonMoveState(this, stateMachine, "Walk", this);
}
protected override void Start()
{
base.Start();
stateMachine.Initialize(chillState);
}
protected override void Update()
{
base.Update();
}
}
// movestate script
using UnityEngine;
public class SkeletonMoveState : EnemyState
{
private Enemy_Skeleton enemy;
public SkeletonMoveState(Enemy _enemyBase, EnemyStateMachine _stateMachine, string _animBoolName, Enemy_Skeleton _enemy) : base(_enemyBase, _stateMachine, _animBoolName)
{
this.enemy = _enemy;
}
public override void Enter()
{
base.Enter();
}
public override void Exit()
{
base.Exit();
}
public override void Update()
{
base.Update();
enemy.SetVelocity(enemy.moveSpeed * enemy.facingDir, enemy.rb.linearVelocity.y);
if (enemy.ISWallDetected() || !enemy.isGroundDetected())
{
enemy.Flip();
}
}
}
// idlestate script
using UnityEngine;
public class SkeletonIdleState : EnemyState
{
Enemy_Skeleton enemy;
public SkeletonIdleState(Enemy _enemyBase, EnemyStateMachine _stateMachine, string _animBoolName,Enemy_Skeleton _enemy) : base(_enemy, _stateMachine, _animBoolName)
{
enemy = _enemy;
}
public override void Enter()
{
base.Enter();
stateTimer = enemy.idleTime;
}
public override void Exit()
{
base.Exit();
}
public override void Update()
{
base.Update();
if (stateTimer < 0)
{
stateMachine.ChangeState(enemy.walkState);
}
}
}
// Enemy script
using UnityEngine;
public class Enemy : Entity
{
[Header("Move info")]
public float moveSpeed;
public float idleTime;
public EnemyStateMachine stateMachine { get; private set; }
protected override void Awake()
{
base.Awake();
stateMachine = new EnemyStateMachine();
}
protected override void Update()
{
base.Update();
stateMachine.currentState.Update();
}
}
// enemy state script
using UnityEngine;
public class EnemyState
{
protected EnemyStateMachine stateMachine;
protected Enemy enemyBase;
private string animBoolName;
protected float stateTimer;
protected bool triggerCalled;
public EnemyState(Enemy _enemyBase, EnemyStateMachine _stateMachine, string _animBoolName)
{
this.enemyBase = _enemyBase;
this.stateMachine = _stateMachine;
this.animBoolName = _animBoolName;
}
public virtual void Update()
{
stateTimer -= Time.deltaTime;
}
public virtual void Enter()
{
triggerCalled = false;
enemyBase.anim.SetBool(animBoolName, true);
}
public virtual void Exit()
{
enemyBase.anim.SetBool(animBoolName, false);
}
}
// entity script
using UnityEngine;
public class Entity : MonoBehaviour
{
#region Components
public Animator anim { get; private set; }
public Rigidbody2D rb { get; private set; }
#endregion
[Header("Collision info")]
[SerializeField] protected Transform groundCheck;
[SerializeField] protected float groundCheckDistance;
[SerializeField] protected Transform wallCheck;
[SerializeField] protected float wallCheckDistance;
[SerializeField] protected LayerMask whatIsGround;
public int facingDir { get; private set; } = 1;
private bool facingRight = true;
protected virtual void Awake()
{
}
protected virtual void Start()
{
anim = GetComponentInChildren<Animator>();
rb = GetComponent<Rigidbody2D>();
}
protected virtual void Update()
{
}
#region Collision
public virtual bool isGroundDetected() => Physics2D.Raycast(groundCheck.position, Vector2.down, groundCheckDistance, whatIsGround);
public virtual bool ISWallDetected() => Physics2D.Raycast(wallCheck.position, Vector2.right * facingDir, wallCheckDistance, whatIsGround);
protected virtual void OnDrawGizmos()
{
Gizmos.DrawLine(groundCheck.position, new Vector3(groundCheck.position.x, groundCheck.position.y - groundCheckDistance));
Gizmos.DrawLine(wallCheck.position, new Vector3(wallCheck.position.x + wallCheckDistance, wallCheck.position.y));
}
#endregion
#region Flip
public virtual void Flip()
{
facingDir = facingDir * -1;
facingRight = !facingRight;
transform.Rotate(0, 180, 0);
}
public virtual void FlipController(float _x)
{
if (_x > 0 && !facingRight)
Flip();
else if (_x < 0 && facingRight)
Flip();
}
#endregion
#region Velocity
public void ZeroVelocity()
{
rb.linearVelocity = new Vector2(0, 0);
}
public void SetVelocity(float _xVelocity, float _yVelocity)
{
rb.linearVelocity = new Vector2(_xVelocity, _yVelocity);
FlipController(_xVelocity);
}
#endregion
}
// Any help with fixing this issue would be greatly appreciated. I copied everything in the tutorial and it should be working fine. Here's a picture

as well of the animator and what is happening.
