Instance error in one of two Identical if statements of scripts

I have a script called WinCondition and a Script called LoseCondition They are not connected in any way but they are almost carbon copies of one another with a slight difference in the name of the functions and the script’s values they check.
WinCondition class

public class WinCondition : MonoBehaviour
{
    ObstacleVariables obstacleVariables;
    [SerializeField] GameObject Result;
    [SerializeField] Text GameResultText;
    int maxPoints = 1000;
    public bool checkWin()
    {
        if (obstacleVariables.count >= maxPoints)
        {
            return true;

        }
        else
        {
            return false;
        }
    }
    void Start()
    {
        obstacleVariables = GameObject.Find("Obstacle_Spawner").GetComponent<ObstacleVariables>();


    }
 
    // Update is called once per frame
    void Update()
    {
        if (checkWin())
        {

                GameResultText.text = "You Win!";
                Result.SetActive(true);
                Debug.Log("You win");

        }
    }
}

LoseConditions script:

public class LoseCondition : MonoBehaviour
{
    PlayerVariables playerVariables;
    [SerializeField]GameObject Result;
    [SerializeField]Text GameResultText;

    void Start()
    {
        playerVariables = GameObject.FindWithTag("Player").GetComponent<PlayerVariables>();
    }
    public bool checkLose()
    {
        if (playerVariables.playerCurrentHP <= 0)
        {
            return true;

        }
        else
        {
            return false;
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (checkLose())
        {
            GameResultText.text = "You Lose!";
            Result.SetActive(true);
            Debug.Log("You Lose");
        }
    }
}

I have set the instances in the scene editor to what I wanted for both scripts. However, The compiler keeps saying there is an instance error with these two lines in WinCondition:

GameResultText.text = "You Win!";
Result.SetActive(true);

But there is no instance error with the almost identical two lines in the lose script:

GameResultText.text = "You Lose!";
Result.SetActive(true);

The 2D forum is not for posts about the C# language or general scripting logic. That’ll be the Scripting forum.

I’ll move your post for you.

I’ve never heard of an “instance error.”

Lots of errors use the word instance, but they are all different errors.

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

Also, just so you know:

Remember the first rule of GameObject.Find():

Do not use GameObject.Find();

More information: https://starmanta.gitbooks.io/unitytipsredux/content/first-question.html

More information: https://discussions.unity.com/t/899843/12