Search Unity

Pause Game and click on game objects

Discussion in 'Scripting' started by sonys222, Jul 26, 2015.

  1. sonys222

    sonys222

    Joined:
    Jun 3, 2015
    Posts:
    32
    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.
     
  2. phoda

    phoda

    Joined:
    Nov 11, 2014
    Posts:
    384
    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;
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    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.
     
  4. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    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.
     
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    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.