Hey everyone, so I have this really simple code where I press the space key and one canvas deactivates while the other activates. Then the opposite when the space key is pressed again, and so on. I just can’t seem to get it to work though. I feel like I’m just messing up the bools in some stupid way. Any help is appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameController : MonoBehaviour {
public GameObject asteroidSpawnerOne;
public GameObject asteroidSpawnerTwo;
public GameObject survivalCanvas;
public GameObject minimapCanvas;
public bool spawnerOneOn;
public bool minimapOpen = false;
// Use this for initialization
void Start ()
{
survivalCanvas.GetComponent<Canvas>().enabled = true;
minimapCanvas.GetComponent<Canvas>().enabled = false;
asteroidSpawnerOne.SetActive(false);
asteroidSpawnerTwo.SetActive(false);
}
// Update is called once per frame
void Update()
{
// Minimap
if (Input.GetKeyDown("space") && !minimapOpen)
{
minimapOpen = true;
OpenInventory();
}
if (Input.GetKeyDown("space") && minimapOpen)
{
minimapOpen = false;
CloseInventory();
}
if (asteroidSpawnerOne.activeInHierarchy == false)
{
spawnerOneOn = false;
}
else
{
spawnerOneOn = true;
}
}
void OpenInventory()
{
survivalCanvas.GetComponent<Canvas>().enabled = false;
minimapCanvas.GetComponent<Canvas>().enabled = true;
}
void CloseInventory()
{
survivalCanvas.GetComponent<Canvas>().enabled = true;
minimapCanvas.GetComponent<Canvas>().enabled = false;
}
}