Im making my first 2D game and im trying to get my character movement to work. I’ve made a script and i have a character controller but my player won’t move in any direction.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterMovement : MonoBehaviour
{
public CharacterController2D controller;
public float runSpeed = 40f;
float horizontalMove = 0f;
void Update()
{
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
}
void FixedUpdate()
{
controller.Move(horizontalMove * Time.fixedDeltaTime, false, false);
}
}
That’s my movement script. when I press play the console give me an error about:
UnassignedReferenceException: The variable m_GroundCheck of CharacterController2D has not been assigned.
You probably need to assign the m_GroundCheck variable of the CharacterController2D script in the inspector.
UnityEngine.Transform.get_position () <0x1daa8b44e70 + 0x0006a> in <3bd64dd808f046b38ba2fb6667d0adc4>:0
CharacterController2D.FixedUpdate () (at Assets/Scripts/CharacterController2D.cs:51)
The problem is when I go on my controller script Visual Studio says there’s no error. I don’t know if the error makes it so i cant move or there’s a problem with my script please help i’ve been trying to do this for hours