c# - How to increase a counter whilst a key is pressed in Unity? -
i creating app turns sphere earth when w pressed speed , s used slow down. unable how find out how make speed increase. here code:
using unityengine; using system.collections; public class spin : monobehaviour{ public float speed; void update () { transform.rotate(vector3.up,speed * time.deltatime); if (input.getkey ("escape")) { application.quit(); } if (input.getkey ("w")) { transform.rotate(vector3.up,speed + 1); } if (input.getkey ("s")) { transform.rotate(vector3.up,speed - 1); } } }
does have idea how can increase speed how long button pressed?
p.s wish write in c#
excuse lack of knowledge unity, looks if statements don't update value of speed
. now, if key pressed, rotating @ value of speed + 1
. speed never changed.
maybe try this?
if (input.getkey("w")) { transform.rotate(vector3.up, speed + 1); speed++; }
Comments
Post a Comment