Hello.
I’m working on my game and I’m new to scripting.Like, just learned a few things with the help of Jonathan Weinberger and I’m trying to make my own game now.
So I have a small problem.
I have the player movement script and I want that, when I hold down the button Left Alt, add +10 speed while holding it down but just once, not every frame and when I release the button, get the normal value again.Here’s the script.
I have a public float called playerSpeed and it's value is 7, I thought this would do the job but it's not working like I wanted to.
----------------------------------------------------------|
if(Input.GetKeyDown(KeyCode.LeftAlt)){ |
playerSpeed += 10; |
} |
|
else if(Input.GetKeyUp(KeyCode.LeftAlt)){ |
playerSpeed -=10; |
} |
--------------------------------------------------------|
So what I want to happen when I hold Left Alt down is, speed +10, if you release the Left Alt, speed back to 7.
What should I do?
I used GetKeyUp there because I think that’s when you release the button (or am I wrong?).
Help me please, thanks.