Author Topic: How to use TweenAlpha?  (Read 14802 times)

Kolyunya

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
How to use TweenAlpha?
« on: January 10, 2014, 07:35:06 AM »
Hello!
I am using NGUI 3.0.8 f7.
I want to tween the alpha of a game object. I try to place the following code int the object script:

  1.        TweenAlpha tweenAlpha = this.gameObject.AddComponent<TweenAlpha>();
  2.         tweenAlpha.from = 1;
  3.         tweenAlpha.to = 0;
  4.         tweenAlpha.duration = 0.3f;
  5.  

When I try to run the program only one child of the game object is being tweened. The object itself is not being tweened.
What am I doing wrong?
Thank you for your help!

Cripple

  • TNP Alpha
  • Full Member
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: How to use TweenAlpha?
« Reply #1 on: January 10, 2014, 08:21:57 AM »
Hi, here is the documentation about tweens : http://www.tasharen.com/forum/index.php?topic=6760.0

If you want to start to tween the alpha of a widget by code, you have to use this :

TweenAlpha.Begin(gameObject, 0.3f, 0.0f);
Graphicstream Dev.

Kolyunya

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: How to use TweenAlpha?
« Reply #2 on: January 10, 2014, 08:27:49 AM »
Cripple, thank you for your answer. I've tried the code you've posted and the result is very same. Only one of the game object's children alpha tweens. The object's alpha is not tweened.
No errors are produced.

Cripple

  • TNP Alpha
  • Full Member
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: How to use TweenAlpha?
« Reply #3 on: January 10, 2014, 08:31:33 AM »
Don't you have another script which could affect the alpha of the game object, such as 'AnimatedAlpha' ?
Graphicstream Dev.

Kolyunya

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: How to use TweenAlpha?
« Reply #4 on: January 10, 2014, 08:36:21 AM »
No, this is a game object with only one script (component)...
The game object has some children and only one of them is being tweened...

Kolyunya

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: How to use TweenAlpha?
« Reply #5 on: January 10, 2014, 08:43:37 AM »
And if I switch TweenAlpha to TweenScale, the whole game object scales successfully, not just one of it's children.

Cripple

  • TNP Alpha
  • Full Member
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: How to use TweenAlpha?
« Reply #6 on: January 10, 2014, 08:48:38 AM »
The game object that you want to tween must have a component UIWidget or at least a component which inherits from UIWidget (such as UISprite, UILabel etc ...)

What kind of object do you want to hide ?
Graphicstream Dev.

Kolyunya

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: How to use TweenAlpha?
« Reply #7 on: January 10, 2014, 08:57:10 AM »
Thank you for an answer. I've just added a "UIWidget" component to the object I want to tween and it now tweens as expected.

The strage thing is that TweenScale works without "UIWidget"...

Cripple

  • TNP Alpha
  • Full Member
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 117
    • View Profile
Re: How to use TweenAlpha?
« Reply #8 on: January 10, 2014, 09:07:51 AM »
This is not strange, this is the normal behaviour. TweenScale tweens the scale of the Transform component of your gameObject (every gameObject has a Transform).

TweenAlpha tweens the alpha value of UIWidget, if you don't have this behaviour on a gameObject, you just can't tween it.

It is like if you wanted to get an haircut at the hairdresser while you are bald.
Graphicstream Dev.

Kolyunya

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: How to use TweenAlpha?
« Reply #9 on: January 10, 2014, 09:17:09 AM »
Cripple, thank you for your help! I used to think each game object has an alpha.

matdru

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 12
    • View Profile
Re: How to use TweenAlpha?
« Reply #10 on: January 10, 2014, 09:19:07 AM »
Oh god, had exact same issue, now i feel like an idiot since it's quite obvious ^^

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to use TweenAlpha?
« Reply #11 on: January 10, 2014, 05:23:55 PM »
It is like if you wanted to get an haircut at the hairdresser while you are bald.
Lol, Cripple :)