Round End Event

Hello! I am creating a round based strategy game and of course there is a button you click and the round ends and then stuff should happen which means that scripts notice when the button was clicked and then execute certain functions. My question is what the best way would be to check when another function in another script ist running. I am kind of new to Unity and C# that’s why I ask.

Currently I am using “Update()” which runs specific functions when an instance of an “integer != 0”; I dont like that because it runs permanently.

So thanks to everyone who has some hints.

Your wording here is quite difficult. Unity uses C# and in it, instances mean a different thing from what you are using it for. “check when another function in another script ist running” This doesn’t make sense, unless by function you mean a coroutine. If you don’t then you should study more to understand C# and basic programming.

Functions aren’t standalone entities that ‘run’ independently. They run in order and only when called. Two functions can’t run at the same time, never (unless you are multithreading, which is very hard in unity).

The correct way of approaching game state control is to actually store a game state in your gamemode class, and use timers to check periodically. Or you can have a game timer, and when it ends the gamemode fires the end round event.

Thanks for your fast reply. I will try to explain it more precisely.

So I have a script on my EndRound-Button which is a basic Button script and then clicked it fires “EndRound()” and does some animation.

So now I have different objects with different scripts in my game which are supposed to run when I click the EndRoundButton.

For example there are civilians which then do stuff, or building which get build etc. They have scripts and I am asking for a way in these scripts to notice when the EndRound-Function is executed/running whatever.

What your looking for is an event system. Unity has one built in than you can look into or you can roll your own.

Its just a place to link an action & a bunch of delegates.

I check that! Thanks!

If you get stuck or hit a dead end let us know :slight_smile: