So, I have a movement script working fine for my character and a blend tree to show the different directional walk animations for my character that seems to work when I change the speed and or vertical/horizontal parameters. The problem is on that the animations for the character don’t work when I hit play. Unity says that I have an unassigned reference exception: I haven’t attached an animator component to my character in the inspector even though I have. Here is My code (I am new) (PS: is it normal for Unity to 999 Warnings and Compiler Errors saying the same thing over and over again?)
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public float moveSpeed;
public Rigidbody2D rb; public Animator animator;
private Vector2 moveDirection; private Vector2 movement;
// Update is called once per frame void Update() { ProcessInputs();
animator.SetFloat("Horizontal", movement.x);
animator.SetFloat("Vertical", movement.y);
animator.SetFloat("Speed", movement.sqrMagnitude);
}
void FixedUpdate()
{
Move();
}
void ProcessInputs()
{
float moveX = Input.GetAxisRaw(“Horizontal”);
float moveY = Input.GetAxisRaw(“Vertical”);
moveDirection = new Vector2(moveX, moveY).normalized;
}
,So, I have a movement script working fine for my character and a blend tree to show the different directional walk animations for my character that seems to work when I change the speed and or vertical/horizontal parameters. The problem is on that the animations for the character don’t work when I hit play. Unity says that I have an unassigned reference exception: I haven’t attached an animator component to my character in the inspector even though I have. Here is My code (I am new) (PS: is it normal for Unity to 999 Warnings and Compiler Errors saying the same thing over and over again?)
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public float moveSpeed;
public Rigidbody2D rb; public Animator animator;
private Vector2 moveDirection; private Vector2 movement;
// Update is called once per frame void Update() { ProcessInputs();
animator.SetFloat("Horizontal", movement.x);
animator.SetFloat("Vertical", movement.y);
animator.SetFloat("Speed", movement.sqrMagnitude);
}
void FixedUpdate()
{
Move();
}
void ProcessInputs()
{
float moveX = Input.GetAxisRaw(“Horizontal”);
float moveY = Input.GetAxisRaw(“Vertical”);
moveDirection = new Vector2(moveX, moveY).normalized;
}