Greetings.
I was following the tutorial on how to activate GameObjects at http://unity3d.com/es/learn/tutorials/modules/beginner/scripting/activating-gameobjects but when I try to compare the active state with activeSelf or activeInHierarchy, I receive the error: Object reference not set to an instance of an object…
public class KeyboardInterfaceHelper : MonoBehaviour {
public bool currentState;
private GameObject interfaceHelper;
void Update ()
{
if (Input.GetKey (KeyCode.K))
{
Debug.Log("You entered the K key...");
currentState = interfaceHelper.activeInHierarchy;
if (currentState == true) {
// The GameObject was active, so we deactivate it...
interfaceHelper.SetActive (false);
}
else
{
// The GameObject was inactive, so we activate it...
interfaceHelper.SetActive (true);
}
}
}
}
The idea is to toggle the GameObject between active and inactive whenever the player press certain key. So, if the GameObject is active it should become inactive and viceversa.
Any ideas why this code does not work?
Thank you.