Author Topic: Can I use any sprite as a button?  (Read 2801 times)

Rapkannibale

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Can I use any sprite as a button?
« on: February 20, 2014, 10:01:03 AM »
Hi,

I am very much new to game development and am looking into tools that will make it easier for to make some very simple prototypes. NGUI seems like an amazing tool, but I do have a question before I decide to buy it.

Is it possible to use any sprite and make it into a button?

For example, let's say I have an image of a tavern building. Could I attach one of the new 2D Box Colliders and the attach a button script to it and take advantage of all the cool functionality that comes with it?

So far all the examples I have seen have been with rectangular buttons.

EDIT: Forgot to ask. Does this extension take advantage of Unity's new 2D features or is it completely separate from those?

Thanks in advance.

Regards!
« Last Edit: February 20, 2014, 10:10:35 AM by Rapkannibale »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can I use any sprite as a button?
« Reply #1 on: February 20, 2014, 10:29:51 AM »
NGUI can use 2D features, but until the next major version of Unity comes out (one after 4.3 cycle), the API is missing important functionality that prevent NGUI from making use of it fully. For now you can draw 2D system's sprites and have them receive NGUI events, but that's about it.

You can turn anything into a button, but you will be using 3D colliders. ALT+SHIFT+C is the shortcut that adds a collider to any NGUI widget and automatically sizes it. It doesn't need to be a widget either. NGUI's event system works with any object that has a collider, so if you want to click on your 3D model, you can.

I strongly advise you to watch the NGUI 3 tutorial first: http://www.youtube.com/watch?v=B66xhIvYF00 -- it explains all the basics.

Rapkannibale

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: Can I use any sprite as a button?
« Reply #2 on: February 20, 2014, 10:35:57 AM »
Thanks Aren!

I watched that tutorial and it was very helpful in deed. I think this extension will be able to do everything I need it to do, especially since I will be starting with very basic concepts.

So if I understand you correctly, I could still drag my 2D image of the tavern into my scene, then add a collider using the contextual menu (or short cut) and then add the button script to it and it should work?

Cheers!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can I use any sprite as a button?
« Reply #3 on: February 21, 2014, 03:23:59 PM »
Depends on how you do it. Dragging a 2D image into the scene with 2D enabled will create a Unity2D sprite for you, which is different from NGUI. You can still give it a 2D box collider and make it receive events if you like, but you will need to attach an NGUI Event System (UICamera) script to the camera that draws it, and set it to Unity2D event mode.

On the other hand if you create an NGUI texture (ALT+SHIFT+T shortcut), then you are working with NGUI instead of Unity2D, and nothing else is necessary. ALT+SHIFT+C to add a box collider, and it's going to be capable of receiving events.