Author Topic: NGUI Button Problems  (Read 6501 times)

KahunaCoder

  • Guest
NGUI Button Problems
« on: October 10, 2013, 11:45:45 PM »
Hello everyone!  I'm sorry if I'm asking a silly question but I tried searching through the forums to see if anyone is having the same problem as I.

I'm currently learning how to use NGUI and I believe I have my gui button set up properly.  It's attached to a panel, it has a collider, the button component, and a texture assigned to it.  I've also defined the different button colors for normal, hover, and pressed.  When I run the game, I noticed that the actual colors aren't changing, but if I look at the preview window with the current button selected, I see the color changing accordingly.

Am I missing something?  Thanks in advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Button Problems
« Reply #1 on: October 11, 2013, 07:33:27 AM »
That's a very basic functionality, and should certainly work just fine. Is your camera set to clear color? What version of NGUI and what version of Unity? Did you create the button using the widget wizard?

KahunaCoder

  • Guest
Re: NGUI Button Problems
« Reply #2 on: October 11, 2013, 08:36:56 AM »
Hi ArenMook. I am using Unity 4.2.1f4 and NGUI 3.0.  I created my UI Root (2D) using the UI Tool.  Once that was done, I created my two sprites attached to the Panel.  One of the sprite is used as a simple background, while the other sprite is being used as the button.  The target in the UIButton script points to the sprite I'm using for the button.

It's strange because I will see it change in the preview window, but in the game window, nothing happens.  I'm not sure how to check whether my camera is set to clear color.  I looked through all the properties in the inspector for the camera but I don't see any option for that.

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Button Problems
« Reply #3 on: October 11, 2013, 08:37:51 AM »
3.0.0? Not 3.0.2? I remember there was an issue with this in an earlier version that got fixed in one of the letter updates of 3.0.0.

KahunaCoder

  • Guest
Re: NGUI Button Problems
« Reply #4 on: October 11, 2013, 08:41:04 AM »
Yes, it says version 3.0.0f in the ReadMe file.  I've also updated my tools (270 to 300)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI Button Problems
« Reply #5 on: October 11, 2013, 08:44:26 AM »
Yeah you need to update to 3.0.2.

KahunaCoder

  • Guest
Re: NGUI Button Problems
« Reply #6 on: October 11, 2013, 08:51:30 AM »
I'll try that right now.  Thanks!

KahunaCoder

  • Guest
Re: NGUI Button Problems
« Reply #7 on: October 11, 2013, 09:46:11 AM »
Hrm...I've updated and reimported my nGUI package, and rebuilt the scene.  I'm still seeing the same issue.  I must be doing something wrong.

http://www.youtube.com/watch?v=muUlRRdpQDY

KahunaCoder

  • Guest
Re: NGUI Button Problems
« Reply #8 on: October 11, 2013, 12:03:33 PM »
So I've gone back and studied how the button tutorial example scene was built.  I've pretty much followed that set up and even added a UIButton Scale script.  The scaling seems to work with the mouse hovers over the button.  But with regards to the button changing colors, it only does it in the preview window when the button's sprite is selected and not in game?

I'm stumped but I won't worry about it anymore.  :-\

Oh, I also ran the example scene and the color change works.

Edit: I'm thinking it could be something with the way I defined my Atlas.  I used TP to generate the atlas.

Solved: I verified that it was the texture atlas.  Looks like I need to apply some kind of shader to it in order for the color script to affect it.  Thanks again for the help!
« Last Edit: October 11, 2013, 12:43:02 PM by KahunaCoder »

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: NGUI Button Problems
« Reply #9 on: October 11, 2013, 06:03:51 PM »
The atlas should use Unlit/Transparent Colored as its shader in the material if you want to color it with vertex colors (which is what a sprite does).