Question by
ikmalhaikal46 · Sep 22, 2020 at 07:41 PM ·
keykeyboard input
Prevent subsequent key input
Hey guys.
So I'm pretty new to Unity. Currently, I'm creating a bowling game. But I have some trouble figuring out how to prevent additional input once an input is entered. This is my code:
void Update()
{
if (Input.GetKeyUp(KeyCode.Space))
GetComponent<Rigidbody>().AddForce(new Vector3(-force, 0, 0));
if (Input.GetKeyUp(KeyCode.LeftArrow))
GetComponent<Rigidbody>().AddForce(new Vector3(0, 0, -5), ForceMode.Impulse);
if (Input.GetKeyUp(KeyCode.RightArrow))
GetComponent<Rigidbody>().AddForce(new Vector3(0, 0, 5), ForceMode.Impulse)
When I pressed Space, I launched the ball from stationary to my force values. But when I keep pressing Space multiple times, the force just adds up. How to prevent that from happening? I just only want the Space input for once and prevent subsequent Space input so that the ball does not speeding up.
Comment
Your answer
