Hello! I’m a beginner coder and I’ve been using this yt tutorial to code top down movement
I keep getting this error:
UnassignedReferenceException: The variable anim of Move has not been assigned.
You probably need to assign the anim variable of the Move script in the inspector.
UnityEngine.Animator.SetFloat (System.String name, System.Single value) (at <96b8a6afc0034a048a05dda6aeede1d8>:0)
Move.Update
My code is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move : MonoBehaviour
{
private Rigidbody2D rb;
public Animator anim;
public float moveSpeed;
public float x, y;
private bool isWalking;
private Vector3 moveDir;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
}
private void Update()
{
x = Input.GetAxisRaw("Horizontal");
y = Input.GetAxisRaw("Vertical");
if(x != 0 || y != 0)
{
anim.SetFloat("X", x);
anim.SetFloat("Y", y);
if(!isWalking)
{
isWalking = true;
anim.SetBool("isMoving", isWalking);
}
}else
{
if(isWalking)
{
isWalking = false;
anim.SetBool("isMoving", isWalking);
StopMoving();
}
}
moveDir = new Vector3(x, y).normalized;
}
private void FixedUpdate()
{
rb.velocity = moveDir * moveSpeed * Time.deltaTime;
}
private void StopMoving()
{
rb.velocity = Vector3.zero;
}
}
Thank you for any advice!