- Home /
Incrementing speed variable during update
I've started a pretty simple endless runner game just to get my bearings in Unity. The path the player runs down is made up of cube tiles, they spawn when the player is in range. I keep count of the amount of tiles that have been spawned, and after x amount of tiles I'd like to increase the player speed to increase the difficulty.
So my player class has a public method IncreaseSpeed, when called it increments the player speed by 1. The IncreaseSpeed method is called from my TileManager class. I want it to be called every 50 tiles, but for debugging I just set it to be called once, after the tile count reaches 50.
Problem is, even though I only call IncreaseSpeed one time, the speed keeps increasing rapidly once called and my player shoots off into space at warp speed.
I know that MonoBehaviour's Update method is tied to the frame rate, so it's probably calling IncreaseSpeed a whole bunch of times while the tile count is at 50. Question is, how can I get this function to only be called one time from the Update method? Or what is a better way of achieving this in Unity? I could also use time elapsed to increase speed, but I'd rather base it on the number of tiles that have been spawned.
Answer by MegasonicZX · Nov 03, 2019 at 10:38 PM
Could you maybe post a screenshot of the code? I have an idea about what you need to do but I feel like you might need a different answer.
Your answer
Follow this Question
Related Questions
How increment only once in function Update 0 Answers
transform.rotation increment slows to a stop 1 Answer
Why does this increment by 2? 2 Answers