- Home /
Print statement to execute multiple times
I want my script to print every time i press space. How should i do this?
The following code only prints "space pressed" regardless of the amount of times space is acutally pressed:
void Update ()
{
if(Input.GetKey("space"))
{
//This does not run more than once
print("space pressed");
}
}
Answer by corriedotdev · Apr 02, 2014 at 05:23 PM
void Update ()
{
if(Input.GetKey("space"))
{
//This does not run more than once
debug.log("space pressed");
}
}
It's "Debug.Log", not "debug.log", and anyway print is merely an alias for Debug.Log, so no difference at all. Also that has nothing to do with the question.
O$$anonymous$$, no need for the attitude online. I have never used print. I now realize that his code needs to be getkeydown.
Answer by Eric5h5 · Apr 01, 2014 at 06:52 PM
Turn off collapse in the console, or just look at the indicator in the console that shows how many times an identical line was printed. Also, you should use GetKeyDown, otherwise GetKey returns true every frame the key is down.
Your answer
Follow this Question
Related Questions
How can I output a raw string \r\n? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Making a bubble level (not a game but work tool) 1 Answer
How can I Update c# version? 2 Answers