i have a script that controls the main menu of my game that uses 2 different keybinds (w/s) for up and down, however, when i use S it triggers twice (taking me to the extras menu) instead of just going down 1 (to the settings menu) despite being a GetKeyDown statement. the debug has shown its triggering twice when using down/s on but up/w works just fine.
this is the script it uses:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class SelectMenuScript : MonoBehaviour
{
// Update is called once per frame
void Update()
{
if (this.cooldown > 0f)
{
this.cooldown -= Time.deltaTime;
}
if (Input.GetKeyDown(KeyCode.S) && this.Play)
{
this.cooldown = 0.1f;
this.Play = false;
this.Settings = true;
this.IMG.sprite = this.SettingsSpr;
this.IMG2.sprite = this.Sam;
this.txt.text = "Something you dont like? Change it here!";
this.Anims.SetTrigger("PlayToSetting");
Debug.Log("key pressed");
}
if (Input.GetKeyDown(KeyCode.W) && this.Settings)
{
this.cooldown = 0.1f;
this.Settings = false;
this.Play = true;
this.IMG.sprite = this.PlaySpr;
this.IMG2.sprite = this.Louis;
this.txt.text = "Select a gamemode and get started!";
this.Anims.SetTrigger("Play");
Debug.Log("key pressed");
}
if (Input.GetKeyDown(KeyCode.S) && this.Settings)
{
this.cooldown = 0.1f;
this.Settings = false;
this.Extras = true;
this.IMG.sprite = this.ExtrasSpr;
this.IMG2.sprite = this.Scratch;
this.txt.text = "Some cool extra stuff to see!";
this.Anims.SetTrigger("Extras");
Debug.Log("key pressed");
}
if (Input.GetKeyDown(KeyCode.W) && this.Extras)
{
this.cooldown = 0.1f;
this.Extras = false;
this.Settings = true;
this.IMG.sprite = this.SettingsSpr;
this.IMG2.sprite = this.Sam;
this.txt.text = "Something you dont like? Change it here!";
this.Anims.SetTrigger("Settings");
Debug.Log("key pressed");
}
if (Input.GetKeyDown(KeyCode.Space))
{
if (this.Play)
{
this.PlayMenu.SetActive(true);
this.Self.SetActive(false);
}
if (this.Settings)
{
this.SettingsMenu.SetActive(true);
this.Self.SetActive(false);
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
if (this.Extras)
{
this.ExtrasMenu.SetActive(true);
this.Self.SetActive(false);
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
this.ShopMusic.SetActive(true);
this.NormMusic.SetActive(false);
}
}
}
public Animator Anims;
public GameObject NormMusic;
public GameObject ShopMusic;
public float cooldown = 0.5f;
public Image IMG;
public Image IMG2;
public Sprite PlaySpr;
public Sprite Louis;
public Sprite SettingsSpr;
public Sprite Sam;
public Sprite ExtrasSpr;
public Sprite Scratch;
public TMP_Text txt;
public bool Play;
public bool Settings;
public bool Extras;
public GameObject PlayMenu;
public GameObject SettingsMenu;
public GameObject ExtrasMenu;
public GameObject Self;
public TMP_Text txt;
public bool Play;
public bool Settings;
public bool Extras;
public GameObject PlayMenu;
public GameObject SettingsMenu;
public GameObject ExtrasMenu;
public GameObject Self;
}