0

I am having that error when I am trying to execute the following code.All it should do is set the panel with the tag "Player1" to false and the one with "Player2" to true.

using UnityEngine;
using System.Collections;

public class Events : MonoBehaviour {

    void Update () 
    {
        if (Variables.Player1Turn == false)
        {
         GameObject.FindGameObjectWithTag("Player1").SetActive(false);
         GameObject.FindGameObjectWithTag("Player2").SetActive(true);
        }
    }
}

Thing is, "Events" and "Variables" are components of empty objects that do not go away.

Here is what "Variables" contains:

using UnityEngine;
using System.Collections;

public class Variables : MonoBehaviour {

    static public string Player1Choice=null;
    static public bool Player1Turn=true;
    static public string Player2Choice=null;
    static public bool Player2Turn=true;
}

Player1Turn goes false when a button on the panel tagged with "Player 1" is pressed.

Note: I do know that the SystemNullReference Exception is thrown at

 GameObject.FindGameObjectWithTag("Player2").SetActive(true);

I, however, cannot find a way around it.

What should I do to make the first panel dissapear and the second one appear without encountering this error?

QRe
  • 27
  • 1
  • 9
  • I edited the original post, I could not find help within the specified link. – QRe Oct 07 '16 at 16:53
  • More than likely, `FindGameObjectWithTag` is returning _null_ on which you then attempt to call `SetActive` resulting in the exception. – Chris Dunaway Oct 07 '16 at 21:41

0 Answers0