Best way to implement a start match button?

I want a start button for a Tower Defense type game. What’s the best way to implement it? Right now, I disable movement and attacks for all enemy units (some of which are visible to the player before the match starts so they can strategize what to build) until the “start button” is hit. However, now I have to check if start == true in every update on every unit.

Is there a better/more efficient way to do this? Pausing the game isn’t an option unless it still lets me drag and drop units from the side ui onto the battlefield for creation.

Set the game timescale to 0 (this will pauze the entire game)

if this is not an option, create a static bool somewhere called isPauzed
and reference the bool in every single script, then you just have to change the bool in 1 place, and make it call some static method that handles everything about pausing.

1 Like

I would recommend using both, set the timescale to 0 (updates will still call so make sure movement is frame rate dependent so it uses time). Then create a static class that has a static bool member and check it on applicable Gameobjects as ShadyProductions says.

You also have the option to disable / enable scripts so they don’t have to check the boolean. This may cause issues if you disable/enable animation / physics components though.

1 Like

Hmm ok. So what you guys are telling me is that in most games with a pause menu out there, there are objects all checking for “is came paused?” every single update/frame? Seems inneficient, but i obviously cant think of something better.

As for time scale, I’ll have to see if it fits my needs. I’m not really pausing the game, I’m just making sure my units don’t move as I drop more onto the battlefield before I hit “start” and they go find something to destroy.

Hey Josh can you elaborate a little more on “checking the class for applicable Gameobjects”? Does that mean just Getting a component from that class such as IsPaused?

Ah, my apologies, some bad wording there, I’ve updated the post and made bold the error below.

What I meant was “…checking the class ON applicable GameObjects.”. I mean that if you have any functionality that is perhaps not based on time, you can check that boolean only on those GameObjects (preventing checks on every GameObject).

As you say you could also write game logic to pause just the enemies, perhaps calling functions on them that stops their movement.