Author Topic: Replace tweenTarget in UIButtonTween  (Read 4907 times)

Mosula

  • Guest
Replace tweenTarget in UIButtonTween
« on: April 27, 2012, 04:35:45 AM »
Hello, I am new in NGUI and testing to see the possibility to use it in my feather projects :D

I am trying to have several windows with tween effect which trigger by the same button.
Therefore, I switch the tweenTarget in UIButtonTween by following coding

                tweenTarget = Instantiate(Resources.Load("PrefabA")) as GameObject;
                tweenTarget.transform.parent = transform.parent;

it works properly when I first click it with PrefabA, 
then I closed the window and click it again which tweenTarget is PrefabB now,
and the new window does come out with nothing loaded.

I have tried several time, which the script go through properly, the information printed on log as well, but it just not appear in the window, neither sprite nor label.
Did I miss something there? or I can't just change the tweenTarget like this?

Please kindly help :) thank u very much

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Replace tweenTarget in UIButtonTween
« Reply #1 on: April 27, 2012, 04:38:33 AM »
Never use Instantiate to spawn UI hierarchies. Use NGUITools.AddChild instead. It will also parent things for you, so you won't need to set the parent.

Also make sure you are using Unity 3.5.1. 3.5.0 has bugs that sometimes cause objects to not load.