In my game, i can only click my button once. Its a button opening a UI menu, which works when i first click it to open it. However its coded for when you click it again, it closes/opens the menu depending on if its closed or open at the moment. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UIFunctions : MonoBehaviour
{
[Header("Objects")]
public GameObject fileExplorer;
public GameObject text;
public GameObject settings;
public GameObject shutdownMenu;
public GameObject shutdownBtn;
[Header("Other")]
public WebcamManager _ss;
public Username _s;
public bool ready = true;
public bool menuOpen = false;
public void Start()
{
_ss.GetComponent<WebcamManager>();
_s.GetComponent<Username>();
}
public void Open(string a)
{
if (ready)
{
if (a == "file")
{
FileExplorer();
}
else
{
if (a == "text")
{
ReadMe();
}
else
{
if (a == "settings")
{
Settings();
}
else
{
if (a == "shutdown")
{
Shutdown();
}
else
{
if (a == "camera")
{
Camera();
}
else
{
Debug.Log("Not a valid name");
}
}
}
}
}
}
}
public void FileExplorer()
{
ready = false;
fileExplorer.SetActive(true);
}
public void ReadMe()
{
ready = false;
_s.usernameText.enabled = true;
text.SetActive(true);
}
public void Shutdown()
{
Debug.Log("Shutdown Menu Clicked");
if(!menuOpen)
{
ready = false;
shutdownMenu.SetActive(true);
menuOpen = true;
}
else
{
ready = true;
shutdownMenu.SetActive(false);
menuOpen = false;
}
}
public void Camera()
{
ready = false;
StartCoroutine(cameraOpener());
}
public IEnumerator cameraOpener()
{
_ss.displayImage.enabled = true;
yield return new WaitForSeconds(0.3f);
_ss.displayImage.enabled = false;
}
public void Settings()
{
ready = false;
settings.SetActive(true);
}
public void Exit(string a)
{
if (ready)
{
if (a == "file")
{
FileExplorerEx();
}
else
{
if (a == "text")
{
ReadMeEx();
}
else
{
if (a == "settings")
{
SettingsEx();
}
else
{
Debug.Log("Not a valid name");
}
}
}
}
}
public void FileExplorerEx()
{
ready = true;
fileExplorer.SetActive(false);
}
public void ReadMeEx()
{
ready = true;
_s.usernameText.enabled = false;
text.SetActive(false);
}
public void ShutdownEx()
{
ready = true;
shutdownMenu.SetActive(false);
}
public void SettingsEx()
{
ready = true;
settings.SetActive(false);
}
}
The code for the menu opening is in the Shutdown void (Line 78-93). Sorry my code is so messy lol. anyone got a fix? The menu just doesnt close when i click the button again, aswell as it doesnt log the button being clicked again. (Its only detecting the first click.) please help