Managing time via framerate rather than time functions. Suggestions ?

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

First off Unity isn’t designed to be a fixed framerate engine.

The docs basically say it’ll try to hit that framerate, but it won’t be perfect… especially if the hardware can’t handle it.

You may want to design your game to be time dependent, rather than frame dependent. The code you have there is easily changed to be time dependent.

Next, it also points out that vsync will override it, so you might want to make sure you set the QualitySettings.vSyncCount to 0:

Appreciated ! That’s a bit clearer now.