Like most code things there's usually a whole bunch of ways of doing things - if you ask how to do something in the most abstract way possible, you might get more of a feedback on possible ways to approach it, rather than double checking if a way you've come up with works (because skimming your code it looks like it should...?)
Is this for the 'walls' or the 'player'?
My only real suggestion would be to put inputs into Update() and the results of those inputs into FixedUpdate() where the physics step happens, because it makes controls feel more responsive - so something like
Code:void Update() { if (input.getbutton("Fire")) { toggle = !toggle; } } void FixedUpdate() { if (toggle) { gravity=1.5; } else if (!toggle) { gravity=-1.5; } }
Also rather than making a fake timer inside of Update(), it might be worth looking into a coroutine that runs at a fixed time step instead?
Sorry not more help, I'm just skimming your sample code - like I say, if you think about things in terms of end result you'll probably get a broader range of suggestions on how to go about it
How do I ensure that a routine runs at a fixed time step? I thought I just had to put the routine in Update and use deltaT to compensate accordingly.
My end goal is to create 2 procedurally generated lines, one being the ceiling, and the other being the floor. They will be y distance apart and that distance will shrink over time. They should scroll to the left at a constant rate.
My short term goal is to create the line for just the ceiling. The ceiling y coordinate is generated off-screen, and then scrolls onto the screen. This is where my solution involves an array of points for the line. The points are equal x distance apart from each other. The array shifting left every n seconds to simulate the ceiling scrolling to the left.
The problem is that I'm guessing this will not play nice with variable framerates. To make it frame independent, I'm guessing I need to make the x distance vary based on deltaT. But for that to work, I would also need to be able to vary the number of points in the line in real time, and that might be very computationally expensive, I'm really not sure. Then again, maybe an array of 10,000 Vector3 being created every frame is not really that computationally expensive after all...I guess I should run some metrics to find out.
What's the best way to run metrics? Just log the time before and after a function call? Or does Unity have built in performance metrics.