Author Topic: [Solved] Clickable UIPanel or Invisible UISprite  (Read 3163 times)

codemaster

  • Guest
[Solved] Clickable UIPanel or Invisible UISprite
« on: December 02, 2012, 05:15:25 AM »
So I'm trying to have an area that's clickable. Two ideas I've had were to (1) have a UIPanel that's clickable or (2) have a UISprite that's invisible. I've tried to do both, but it seems UIPanels, even with a collider, don't handle clicks and UISprites pretty much require, well, a sprite image.

Any thoughts on how I could go about doing this?
« Last Edit: December 02, 2012, 08:49:53 PM by codemaster »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Clickable UIPanel or Invisible UISprite
« Reply #1 on: December 02, 2012, 09:49:27 AM »
Just create a game object and add a collider to it.

Anything with a collider can receive events, assuming its game object is on a layer that gets masked by UICamera's event mask.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Clickable UIPanel or Invisible UISprite
« Reply #2 on: December 02, 2012, 10:35:21 AM »
Make an empty gameobject in your hierarchy.

Put a collider on it, set the size to what you want it to be (turn on gizmos to see it, the green rectangle).

Attach your own script (component) with void OnClick() in it.

And there you go.

codemaster

  • Guest
Re: Clickable UIPanel or Invisible UISprite
« Reply #3 on: December 02, 2012, 08:49:38 PM »
D'oh, I forgot to place them in the right layer :-[
Thanks guys! working spectacularly, now!