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?