I am currently working on a camera to follow a Game Object with a tag “Player”. I was trying to make the camera auto-track the player once they’re destroyed/gone on the scene however I am getting a NullReferrenceException error and it’s kinda annoying showing on my console and I believe it would cause problems on the game I’ve been working on.
Here’s how I tried to approach the problem:
void Update()
{
if (playerObject == null) //if no object that has "Player" tag found
{
Debug.Log("Camera Status: Finding player");
try
{
tracker(); //a function that contains the line where it finds the "Player" tag.
}
catch (NullReferenceException ex)
{
Debug.Log(ex); // Just a code trying if it works
}
}
}
I also recently tried to transfer that on the LateUpdate but still remains the same. How do I handle this error in Unity?