using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum PlayerState
{
walk,
attack,
interact,
stagger,
idle
}
public class PlayerMovement : MonoBehaviour
{
public PlayerState currentState;
public float speed;
[SerializeField] private Stat health;
bool attack;
private Animator animator;
public Rigidbody2D myRigidBody;
private Vector3 change;
private void Awake()
{
health.Initialize();
}
// Start is called before the first frame update
void Start()
{
currentState = PlayerState.walk;
myRigidBody = GetComponent();
animator = GetComponent();
animator.SetFloat(“Look X”, 0);
animator.SetFloat(“Look Y”, -1);
}
// Update is called once per frame
public void Knock(float knockTime, float damage)
{
//a place for damage stuff.
health.CurrentVal -= damage;
CombatTextMgr.Instance.CreateText(transform.position, damage.ToString(), Color.white);
StartCoroutine(KnockCo(knockTime));
}
void Update()
{
change = Vector3.zero;
change.x = Input.GetAxisRaw(“Horizontal”);
change.y = Input.GetAxisRaw(“Vertical”);
if(Input.GetButtonDown(“attack”) && currentState != PlayerState.attack && currentState != PlayerState.stagger)
{
StartCoroutine(AttackCo());
}
else if (currentState == PlayerState.walk || currentState == PlayerState.idle)
if (change != Vector3.zero)
{
MoveCharacter();
animator.SetFloat(“Look X”, change.x);
animator.SetFloat(“Look Y”, change.y);
animator.SetBool(“moving”, true);
}
else
{
animator.SetBool(“moving”, false);
}
}
private IEnumerator AttackCo()
{
animator.SetBool(“attack”, true);
currentState = PlayerState.attack;
yield return new WaitForSeconds(.4f);
animator.SetBool(“attack”, false);
currentState = PlayerState.walk;
}
void MoveCharacter()
{
change.Normalize();
myRigidBody.MovePosition(transform.position + change * speed * Time.deltaTime);
}
private IEnumerator KnockCo(float knockTime)
{
if (myRigidBody != null)
{
yield return new WaitForSeconds(knockTime);
myRigidBody.velocity = Vector2.zero;
currentState = PlayerState.idle;
myRigidBody.velocity = Vector2.zero;
}
}
}
The bolded line above is where it says the exception is located, but I can’t tell which part of it has the issue.