Ejemplo n.º 1
0
    void OnGUI()
    {
        Event e = Event.current;

        if (e.isKey && waitForInput && e.keyCode != KeyCode.Return && e.keyCode != KeyCode.Escape && e.keyCode != KeyCode.None)           //None must be checked because when the key is lifted, it sends a None event.//
        {
            bool buttonAssigned;
            buttonAssigned = GameConstants.CheckButtonExists(e.keyCode);
            if (!buttonAssigned)
            {
                soundEffect.PlaySoundEffect("Confirm");
                typeof(GameConstants).GetField(buttonToChange).SetValue(null, e.keyCode);
                GameConstants.ReloadButtonsAsigned();
                currentButtonSelected.GetComponent <Button>().interactable = true;
                EventSystem.current.SetSelectedGameObject(currentButtonSelected);
                waitForInput = false;
                ShowButtons();
            }
            if (e.type == EventType.KeyUp && waitForInput)               /////Has to be played when key up, otherwise it replays the sound effect constantly while pressed
            {
                soundEffect.PlaySoundEffect("Wrong");
            }
        }
    }