Author Topic: Make a sprite fade out on mouse click  (Read 3913 times)

gameCoder

  • Guest
Make a sprite fade out on mouse click
« on: January 07, 2013, 03:58:05 PM »
Hi,
I have code that already detects a mouse click on a sprite , based on the presence of its collider.

Is there a way I can make a UISprite fade out on mouse click?

I changed the alpha to 0 and that totally made the sprite disappear. No other alpha value seems to have any effect.

Thanks

cayou

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 3
  • Posts: 90
    • View Profile
Re: Make a sprite fade out on mouse click
« Reply #1 on: January 07, 2013, 04:01:56 PM »
You have to change the alpha value on time.
The basic way is to change it into an Update function, decrementing it like this:

  1. float speed; //speed of fadeoff.
  2.  
  3. void Update()
  4. {
  5.     myWidget.alpha -= Time.deltaTime * speed;
  6. }
  7.  

Maybe it exists a tween function in NGUI that does the job for you, or you can also use a tween plugin (like HOTween) to perform it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Make a sprite fade out on mouse click
« Reply #2 on: January 07, 2013, 11:10:54 PM »
UITweenAlpha.Begin(...).