Author Topic: Time.timeScale=0 breaks the buttons  (Read 15686 times)

Devil_Inside

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Time.timeScale=0 breaks the buttons
« on: November 30, 2013, 07:02:36 PM »
Setting Time.timeScale to 0 on a button press, will freeze that button in the Hovered state, and will make that button "selected", so you can't press any other button while timeScale remains set to 0.
To reproduce:
1. Create a new Scene and add a new 2D UI,
2. Add 2 buttons to the panel: Button1 and Button2
3. Add a script that simply sets Time.timeScale=0; as the "OnClick" target for Button1
4. Add a script that prints "Hello" to console as the "OnClick" target for Button2
5. Run the game, click Button1 to "stop" the time.
6. If you try to click Button2 now, you'll see that it doesn't respond, but instead Button1 is being clicked.

JMab

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Time.timeScale=0 breaks the buttons
« Reply #1 on: November 30, 2013, 09:45:47 PM »
I noticed that too. I think it would be good if all of the NGUI classes used the Realtime object for timing.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Time.timeScale=0 breaks the buttons
« Reply #2 on: December 01, 2013, 09:42:45 AM »
Looks like I broke it recently. You can fix it by adding the following code to the beginning of the UICamera.ProcessMouse function:
  1.                 if (Time.timeScale <= 0.25f)
  2.                 {
  3.                         if (!Raycast(Input.mousePosition, out lastHit)) hoveredObject = fallThrough;
  4.                         if (hoveredObject == null) hoveredObject = genericEventHandler;
  5.                         for (int i = 0; i < 3; ++i) mMouse[i].current = hoveredObject;
  6.                 }

Devil_Inside

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Time.timeScale=0 breaks the buttons
« Reply #3 on: December 01, 2013, 01:13:39 PM »
Thanks!

wom

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Time.timeScale=0 breaks the buttons
« Reply #4 on: December 02, 2013, 05:06:08 AM »
Argh!  I just spent ages tracking this down.  And the worst thing is - I scanned this topic only a day or two ago, just didn't process what I was reading properly.  How embarrassment  :-[

Eugene

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Time.timeScale=0 breaks the buttons
« Reply #5 on: December 06, 2013, 02:57:26 PM »
Thank YOU, ArenMook!
You just made my day. I was bummed out it didn't work, and I'm so glad I found your solution that fixed this problem almost instantly, that I've registered on this site just to tell you how grateful I am for this!
I probably would've spent up to a week fixing this on my own. Well done, sir, well done!

Holdwick

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Time.timeScale=0 breaks the buttons
« Reply #6 on: December 06, 2013, 03:26:41 PM »
Thanks so much!
Kyle "Goin' for it since the early 90s" Holdwick
Developer | REFRACT
@kyleholdwick