Author Topic: UIPlayTween.resetIfDisabled Not Working for my Powerup Menu  (Read 1788 times)

maxdev

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 11
    • View Profile
UIPlayTween.resetIfDisabled Not Working for my Powerup Menu
« on: January 10, 2015, 07:12:17 AM »
Hello,

I am implementing a powerup menu that that has icons pop out and close after the player clicks a powerup.
My issue is I want the powerup menu's icons to reset to their hidden positions after the panel holding the menu is set to inactive.
So I figured the resetIfDisabled should do just that, so I call that in the start function on the power menu script.

This is how my hierarchy is set up:

--PowerupPanel
----PowerupMenu <-- Has following script attached, a collider and a UIPlayTween(Play Direction is set to Toggle) for each Powerup.
--------PowerupA - Has Tween Position to pop the powerup out.
--------PowerupB - Has Tween Position to pop the powerup out.
--------PowerupC - Has Tween Position to pop the powerup out.

The script I have attached to the PowerupMenu:

  1. void Start () {
  2.         foreach (UIPlayTween ptt in gameObject.GetComponents<UIPlayTween>())
  3.         {
  4.             ptt.resetIfDisabled = true;
  5.         }
  6.  
  7.         foreach(UIPlayTween pt in transform.GetComponentsInChildren<UIPlayTween>(true))
  8.         {
  9.             pt.resetIfDisabled = true;
  10.         }      
  11.         }
  12.  

What happens is the powerup menu works but when I hide and unhide the panel the state they
are in stays, meaning they dont return to their original hidden positions.

Any help or insight would be very appreciated!

Thanks,
Max

maxdev

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: UIPlayTween.resetIfDisabled Not Working for my Powerup Menu
« Reply #1 on: February 28, 2015, 05:28:54 AM »
Hey, any input on this? Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPlayTween.resetIfDisabled Not Working for my Powerup Menu
« Reply #2 on: March 01, 2015, 05:03:27 PM »
The way "reset if disabled" flag works is: when the UIPlayTween is about to activate a tween to play an animation it checks -- is it disabled? If so, and the flag is true, then it will reset the tween to the beginning. This means that this flag only affects tweens directly started by UIPlayTween.

Your script does its logic in Start(), and Start() only runs once, so I'm not sure what the point of what you're doing is... If you are trying to manually reset tweens in OnDisable(), then why not just write a script that has OnDisable() instead of Start(), and does this inside:
  1. void OnDisable()
  2. {
  3.     tween.Play(true);
  4.     tween.ResetToBeginning();
  5. }