Hello I try to create my first game in 2D and i have question. When a game is paused, why i can still click in game objects and get a scores ? How i can fix this problem ? I might add that I care to pause after completing the game and display the final result.
if you have only ui buttons after pause then you can after calling pause function add Time.timeScale = 0f.
and when you press resume set Time.timeScale = 1f;
How are you clicking on objects?
The simplest way is to check if the game is paused in your clicking code. But this is cumbersome to manage in the long term.
My favourite method is to put an invisible object that blocks clicks between the pause menu and the game.
I would say that I dislike that idea as it sounds a bit hack-ish, but honestly when you’re cutting THAT many hours off of your work in the long run, it’s hard to argue. You could probably also just disable the raycasters, I suppose.
It’s more the reliability I like. You forget to disable one raycaster, or do one check in your clicking code, and the system breaks.
You could also implement the checking into your raycaster or event system. Perhaps implement some sort of layer based system.
But ultimately just putting up a panel to block clicks is far simpler. It’s also easy to configure. And it’s fairly fail proof.