I am within the means of organising keyboard navigation for my sport. I am having an issue the place keybinds that ought to solely work whereas particular sport objects are energetic are firing on a regular basis.
Screenshot of DebugLog & Hierarchy.
Right here is the code for the keybind management:
utilizing UnityEngine;
public class KeyboardControl : MonoBehaviour
{
public GameObject mainMenuButtonContainer;
public GameObject typingContainer;
UIManager ui;
[SerializeField]
EmailManager em;
[SerializeField]
DBManager db;
non-public void Awake()
{
ui = GetComponent<UIManager>();
}
non-public void Replace()
{
if (!typingContainer.activeInHierarchy)
{
CheckKeybind();
}
}
void CheckKeybind()
{
// Predominant Menu Navigation
if (mainMenuButtonContainer.activeInHierarchy)
{
Debug.Log("Predominant menu buttons energetic? : " + mainMenuButtonContainer.activeInHierarchy);
if (Enter.GetKeyUp(KeyCode.S))
{
ui.StoryMode();
}
if (Enter.GetKeyUp(KeyCode.I))
{
em.ShowInbox();
}
if (db.freeplayList.Rely > 0 && Enter.GetKeyUp(KeyCode.F))
{
ui.FreePlay();
}
if (Enter.GetKeyUp(KeyCode.T))
{
ui.Stats();
}
if (Enter.GetKeyUp(KeyCode.E))
{
ui.Settings();
}
if (Enter.GetKeyUp(KeyCode.C))
{
Debug.Log("Pressed Credit Keybind");
}
if (Enter.GetKeyUp(KeyCode.X))
{
ui.ConfirmQuitRequest();
}
}
// Electronic mail Panel Navigation
if (inboxPanel.activeInHierarchy)
{
if (Enter.GetKeyUp(KeyCode.C))
{
em.HideInbox();
}
if (inboxNextButton.activeInHierarchy && Enter.GetKeyUp(KeyCode.N))
{
em.NextEmail();
}
if (inboxPrevButton.activeInHierarchy && Enter.GetKeyUp(KeyCode.P))
{
em.PreviousEmail();
}
}
}
}
I’ve tried:
- utilizing activeSelf as a substitute of activeInHierarchy.
- transferring the keybind checks into their very own operate, out of replace (present state).
The conditional test for typing container in replace works, because the keybinds will not be registered if the typing container is energetic, however the inverse appears to not be true for the mainMenuButtonContainer.