Author Topic: Show/Hide pause button.  (Read 4534 times)

quenhoai

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 6
    • View Profile
Show/Hide pause button.
« on: September 15, 2014, 04:30:53 AM »
Hello all,

I testing with pause button and a panel. I want hide pause button after press it, then the panel apear. When i close this panel, the pause button apear again.

My script (with NGUI):
  1. public class popup : MonoBehaviour {
  2.  
  3.         public GameObject popUpWindow;
  4.        
  5.         void OnClick ()
  6.         {
  7.                 if (Time.timeScale == 0)
  8.                 {
  9.                         Time.timeScale =1;
  10.                 }
  11.                 else
  12.                 {
  13.                         Time.timeScale =0;
  14.                 }
  15.                 if (popUpWindow)
  16.                 {
  17.                         if (popUpWindow.activeSelf )
  18.                         {
  19.                                 popUpWindow.SetActive (false);
  20.                         }
  21.                         else
  22.                         {
  23.                                 popUpWindow.SetActive (true);
  24.                         }
  25.                 }
  26.         }
  27. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Show/Hide pause button.
« Reply #1 on: September 15, 2014, 04:34:46 AM »
Is there a question there?

quenhoai

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Show/Hide pause button.
« Reply #2 on: September 15, 2014, 07:12:02 AM »
I'm sorry, :) (there is not Edit funtion)

With my script, the pause button dont hide after i click it, and panel visible when start this scene.

How do i do to pause button hide after click and panel visible when start scene.

Thanks you very much.


quenhoai

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Show/Hide pause button.
« Reply #3 on: September 15, 2014, 09:04:58 AM »
Please help me.

quenhoai

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Show/Hide pause button.
« Reply #4 on: September 15, 2014, 09:22:40 PM »
code to make button appear/disappear is:

"this.gameObject.SetActive (false);"

But i can not make popup appear after press pause button. Now popup and pause button both appear/disappear. How can i do?

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Show/Hide pause button.
« Reply #5 on: September 16, 2014, 09:27:31 AM »
I'm sorry, I am having a hard time understanding what you wrote. The pause button will disappear if it's a child of the game object you're disabling. You should never do "gameobject.setActive(false)" because this disables the object on which the script is running. Instead, create a script with a public property referencing a target game object, and make sure this script is not underneath the object you're disabling.

quenhoai

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Show/Hide pause button.
« Reply #6 on: September 16, 2014, 10:37:20 PM »
I'm sorry, I am having a hard time understanding what you wrote. The pause button will disappear if it's a child of the game object you're disabling. You should never do "gameobject.setActive(false)" because this disables the object on which the script is running. Instead, create a script with a public property referencing a target game object, and make sure this script is not underneath the object you're disabling.

Very sorry about my English, i trying to improving. And with my goal, I'm fixed it. But i will make other follow your way, ArenMook. Thanks you very much. :))