Author Topic: How to stop event from propagating?  (Read 4662 times)

danilofaria

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
How to stop event from propagating?
« on: April 24, 2016, 12:50:36 PM »
I've been having a problem with NGUI.

If I touch a button in the UI and there is some game object right underneath it, then it also receives the event (more specifically OnMouseDown in my case).

This looks really bad and I don't want the objects to receive this event if the UI has received the even first.

What can I do about this?

Thanks!
Danilo

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to stop event from propagating?
« Reply #1 on: April 25, 2016, 12:53:45 PM »
OnMouseDown is a Unity event. It's not an NGUI event, which is why NGUI can't do anything about it.

You should be using OnPress (bool isPressed) instead.

danilofaria

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: How to stop event from propagating?
« Reply #2 on: April 25, 2016, 06:49:01 PM »
I added the OnPress (bool isPressed) method to my game object script but nothing happens. It doesn't get triggered.
What other steps do I need to take?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to stop event from propagating?
« Reply #3 on: April 25, 2016, 10:34:41 PM »
You need to make sure that the camera that draws this game object has UICamera script attached.

danilofaria

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: How to stop event from propagating?
« Reply #4 on: April 26, 2016, 10:51:04 PM »
It works! Thanks!