Hey, I’m currently working on unity for a college project. I’m doing a fighting game, and the genre requires time calculation to be made using a framerate capped at 60fps. Here’s what I did so far (implemented on the Space Shooter tutorial, to have a wave spawning every 3s)
void Start()
{
Application.targetFrameRate = 60;
clock = 0;
}
void Update()
{
if (clock == int.MaxValue)
{
clock = 0; //anti-overflow
}
else
{
clock++;
}
}
void FixedUpdate ()
{
if (clock % 180 == 0)
{
SpawnWaves(); //spawn a wave every 3s (180 frames)
}
}
The thing is, I’m not too sure if there is a way to make something cleaner, as I’ve stumbled upon a Time.frameCount method, and I can’t figure out how does this method works, even after reading the documentation.
Also, is using Application.targetFrameRate = 60 the right thing to do to cap the game at 60 fps?
EDIT: When I run the game in unity, the “statistics” window tells me framerate is not constant and hovers around 190-ish even though I called Application.targetFrameRate = 60