I am using Unity and C# for the first time, I am atemping to make a 2D platformer game and I am following this tutorial https://www.youtube.com/watch?v=TcranVQUQ5U for the code. I've been following along exactly for everything with the Rigidbody and the code, but when I tested my horizontal movement it didn't work. Here is my code:
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
private Rigidbody2D body;
private void awake()
{
body = GetComponent<Rigidbody2D>();
}
private void Update()
{
body.velocity = new Vector2(Input.GetAxis("Horizontal"), body.velocity.y);
}
}
Here is my error:
NullReferenceException: Object reference not set to an instance of an object PlayerMove.Update () (at Assets/Scripts/PlayerMove.cs:14)