I don’t understand why Time.deltaTime is used here, what exactly does it do? I know that it’s used so movement is the same on every computer it basically counts the time instead of the fps but I still don’t understand the code in general, please explain.
If the game runs at 100 frames per second, then Time.deltaTime will equal .01. that way if you have an object you want to move at 5 units per second, when you multiply by deltaTime it will only move .05 units in a single frame. And since the game is running at 100 fps, after 100 frames have passed the object will have moved 5 units and 1 second of time will have passed. Tada! 5 units per second!
In other words, using Time.deltaTime allows your code to be framerate-independent. For example let’s say in Update (which is called once per frame), move the character forward by 2 units. If the game is running at 30fps, after 1 second, your character will have moved by 60 units. But if the game is running at 60fps, your character will have moved 120 units. So by multiplying how far you want to move by Time.deltaTime, you ensure that no matter how long each frame is, your character will still be moving forward at the same speed regardless of the current framerate.