Why are you using While Loops? I think this can easily be done by using an IF statement. But while loop shouldn’t be a problem anyways. Try to put this script on another object and see if it’s working fine or not. Maybe another project.
Also use the code tags from next time. Makes code easier to read. In text editor , INSERT > CODE.
If statement is working, but not the way i want. I can’t use the “break” part in if statement.
I want ,when user press p, the power increase and when he release the key the loop ends (simple)…
The question is , is it turning into an infinite loop ,or something like that ?
Input.GetKey returns true on every frame that key is down.
One frame is the time it takes for all of the Update functions to run.
Your while-loop will keep running until the key isn’t registered as down anymore, and prevent the Update from finishing. Since your Update needs to finish before the key is registered as down, the while-loop will never exit.
“void start” is a lot worse, as it compiles and does nothing. I’m pretty sure OP’s code isn’t copy-pasted, though.
hey, @willgoldstone , maybe a console warning about Unity-Methods written with lowercase letters could be implemented? I’ve probably answered half a million questions on UA and here where the solution was “put a big U on Update”.