Error on running animating movement code,Question on animation movement
https://www.youtube.com/watch?v=whzomFgjT50&list=PLlay-Dk_UDFYjPk5p6fNhVpQo3JXWQTNV∈dex=3&t=667s This I where I copied movement code, It took a while to copy it all down, and after I followed everything it said to... I got this
UnassignedReferenceException: The variable animator of PlayerMovement has not been assigned. You probably need to assign the animator variable of the PlayerMovement script in the inspector. UnityEngine.Animator.SetFloat (System.String name, System.Single value) (at :0) PlayerMovement.Update () (at Assets/PlayerMovement.cs:18)
Heres my code using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMovement : MonoBehaviour { public float moveSpeed = 5f; public Rigidbody2D rb; public Animator animator; Vector2 movement;
// Update is called once per frame
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
animator.SetFloat("Horizontal", movement.x);
animator.SetFloat("Vertical", movement.y);
animator.SetFloat("Speed", movement.magnitude);
animator.SetFloat("Speed", movement.magnitude);
}
void FixedUpdate()
{
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
}
}
I believe I did it all correctly, what did I do wrong? Need it for a High school project would greatly appreciate it