- Home /
how would i increment numbers?
so i want to have it where i push on a key and it takes a number and increments it, and when i let off the key the number decrements back down to zero. any ideas or way i could go about doing this in java?
Answer by aldonaletto · Nov 17, 2012 at 11:00 PM
The simplest way is to increment the value in GetKeyDown and decrement it in GetKeyUp. Supposing that number is the variable where the number is stored and the key C increments/decrements the value, the code could be something like this:
var number: int = 1;
function Update(){
if (Input.GetKeyDown("c")){
number += 1;
}
if (Input.GetKeyUp("c")){
number -= 1;
}
}
This worked really well for me, even 5 years into the future!
Your answer
Follow this Question
Related Questions
yield WaitForSeconds(1) ends with this error:ArgumentException: method return type is incompatible 2 Answers
Problem with call static methods in plugin 0 Answers
How to Instantiate prefab as child? (Java) 1 Answer
Sending bytes over network 0 Answers
Getting this error when trying to run a game on android 2 Answers