Author Topic: Event when not colliding with any buttons?  (Read 5252 times)

UnityJP

  • Guest
Event when not colliding with any buttons?
« on: July 16, 2012, 01:30:24 PM »
Hi everyone,

I'm trying to use build a controller for my Android game and was looking for some suggestions on how to setup my interface with NGUI buttons.  The control scheme is essentially two-fold, first the player touches the screen to set a target for where they want to fire a weapon.  Then, depending on what button they push, a specific weapon is fired.  The issue I'm running into is that with the touch control I have setup right now, the target is moving when I select the button.  I've tried to do some kind of check to see if the touch collides with any buttons in the scene but I was having trouble getting that working and its seems overly complicated.

So is there a system or script I can attach to the UICamera that only receives events (like OnClick) when a collider isn't hit? Does NGUI send events to all colliders if they are stacked?

Thanks in advance,
JP

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: Event when not colliding with any buttons?
« Reply #1 on: July 16, 2012, 01:39:22 PM »
That seems backwards.  Why wouldn't you click the weapon to select the type of attack/action you want to take and then tapping in the game client area is a "fire that type of weapon" action.

Unless is somehow makes more sense to have a target reticle that is placed... but it does, indeed, seem a frustrating way to spawn actions.  You'd have to estimate positions of moving targets and place the reticle out front of them, then hope you can click the attack type and get the timing right.  Of course, your fingers are out of the way so it is easier to see the result.

Having the order reversed means that the attack is initiated on the tap of the target rather than the tap of the weapon selection, which means the user's fingers are possibly over the screen and preventing visual display of something.

Really, this isn't an NGUI question.  It's a game design question.

(I may have missed the intent of your question, though.  Any object with a collider receives NGUI events if it's part of the UICamera's event mask.  So it should be fairly easy to have your playfield incorporate colliders that get the events and then grab the event's coordinates to place the target or fire the weapon or whatever.)
« Last Edit: July 16, 2012, 01:42:41 PM by JRoch »

UnityJP

  • Guest
Re: Event when not colliding with any buttons?
« Reply #2 on: July 16, 2012, 01:53:45 PM »
The way we have envisioned the game-play we think it will work but we may get to a point where we decide that it is either frustrating or unintuitive.  I do see your point though, so thanks for the input.

But game design aspects aside, I'm really just wondering if there is a way with NGUI to receive say an OnClick() event when anything but the buttons I have on the screen are tapped.  Would it work if I had a global collider that was behind the other colliders? Or does NGUI send events to all colliders if they are stacked?

I'm continuing to experiment with this, just wondering if anyone had done a system like this, or knew a way to implement a system like this using NGUI already.

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: Event when not colliding with any buttons?
« Reply #3 on: July 16, 2012, 02:14:01 PM »
My understanding is that the top-most collider that is struck by a ray cast from the camera through the viewport is the object that gets sent most events.  However, the UICamera tracks some states, so that things like OnSelect will send (state:false) events to the former target as it loses focus.

Anyhow, yes, you could have a global collider in the NGUI camera space, or you could have your colliders in world and attach a copy of UICamera.cs to your world camera with an appropriate event layer mask.  If you're just concerned about screen coordinates, doing it in NGUI 2D camera space is really simple.  If you want to allow people to click directly on gameobjects with colliders attached, it's probably best to do it through your world main camera.