I followed a tutorial on "How to make a video game" by Brackeys and I changed a few things but still copied most of what he did. After I copied his code on collision (episode 9) I got an error when my player crashed into another car saying "Null Reference Exception".
I tried looking up solutions online and making sure I did it right but its all confusing and idk.
using UnityEngine;
public class ColiisionScript : MonoBehaviour
{
public forward movement;
void OnCollisionEnter(UnityEngine.Collision collisionInfo)
{
if (collisionInfo.gameObject.tag == "StrangerThings")
{
GetComponent<forward>().enabled = false;
FindObjectOfType<GameManager>().EndGame();
}
}
}
I wanted my game to restart a few seconds after the player hits an obstacle or another car but instead, the game pauses and tells me I have an error.