- Home /
GetKeyDown held for too long
Hi, I have a script that loads through overviews of levels but only lets you go to the next level if you have 3 stars in the current one, I am using the bumpers on an xbox controller to change between level however if you are on level one and click right bumper it takes you to level 3 if you have 3 stars on level 2 already. I have tried to change where the input is on the code. The problem is because when I load up level 2 selection it sets the level selection to 2, and then it has the 3 stars so instantly jumps up again, this is all in function so cannot have a wait code in it as I have tried that, any help?
if (Input.GetKeyDown(KeyCode.Joystick1Button5))
{
if (level_selection == 1)
{
if (PlayerPrefs.HasKey("Hedge_10x10_01_Stars"))
{
if (PlayerPrefs.GetInt("Hedge_10x10_01_Stars") >= 3)
{
level_selection += 1;
}
}
}
if (level_selection == 2)
{
if (PlayerPrefs.HasKey("Hedge_10x10_02_Stars"))
{
if (PlayerPrefs.GetInt("Hedge_10x10_02_Stars") >= 3)
{
level_selection += 1;
}
}
}
if (level_selection == 3)
{
if (PlayerPrefs.HasKey("Hedge_10x10_03_Stars"))
{
if (PlayerPrefs.GetInt("Hedge_10x10_03_Stars") >= 3)
{
level_selection += 1;
}
}
}
Answer by Captain_Pineapple · Apr 30, 2018 at 01:38 PM
If i got your question right you want it to change only one level per buttonDown? Then just change your if(levelselection == x) to an if/else if/else if statement istead of the current if/if/if. That way only one of the cases will be active per click.
Note at this point that you can not "hold a button too long" when you use Get$$anonymous$$eyDown. It will always trigger only once per button click. Perhaps read into the difference between Get$$anonymous$$eyDown/Get$$anonymous$$ey/Get$$anonymous$$eyUp
Your answer
Follow this Question
Related Questions
I need help with a CharacterMotor script error in Unity5. This is formatted in Javascript. 0 Answers
Moving Animations 3 Answers
Need help with combining meshes 1 Answer
Why am I only allowed to trigger my dash script once? 2 Answers
How do perform the operations as per the commands at client side in socket unity? 0 Answers