Author Topic: OnClick  (Read 5209 times)

Alex

  • Guest
OnClick
« on: April 13, 2012, 05:33:27 PM »
Hi,
I would like to be able to receive OnClick event from some of my gui buttons, in one place.
for example suppose i have this hierarchy:
*GameMenu <-- i want a central script to attach here with OnClick  that report what GO was pressed
**Camera
***Anchor
****btnPause <-- what script should i attach here? i tried UIEventListener but it's not fire OnClick
on GameMenu
****btnResume<-- also script attach here
****btnRestart<-- also here

any suggestion?

Thanks

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: OnClick
« Reply #1 on: April 13, 2012, 05:52:16 PM »
It should have a Collider on it, that's it.

Then any script that has the method

public void OnClick()
{...}

will be called on the click.

That means you can set your own scripts to capture the OnClick. If you're further interested in how it's done, look in UICamera.cs

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnClick
« Reply #2 on: April 13, 2012, 06:05:21 PM »
UIEventListener is supposed to be used via code, and only via code. UIEventListener.Get(objectToListenTo).onClick += YourClickFunction;

John

  • Guest
Re: OnClick
« Reply #3 on: April 14, 2012, 12:21:16 AM »
It sounds like you have not looked at UIButtonMessage script.  My setup is very much like yours.  I attach a UIButtonMessage script to each button and then set the Target (using the Inspector) to my top-level window (GameMenu, in your case).

Did you already try that or is that what you were looking for?

Alex

  • Guest
Re: OnClick
« Reply #4 on: April 14, 2012, 02:54:28 AM »
Hi,
I must admit that i never saw the UIButtonMessage but it looks exactly what i need.
Thanks