Author Topic: using scenery to obfuscate ui events?  (Read 2249 times)

w3iRd c0De

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
using scenery to obfuscate ui events?
« on: June 22, 2013, 06:03:53 AM »
Hi.  I've come across an interesting little problem and was wondering about the best way to proceed.  Apologies if this is covered in another thread but I could not find one.

I have 4 robot characters in a room.  Each of them has a box collider on my 3d ui layer.  The object with the collider has a script to detect hover and click events so I can make something happen when I click on the robot.  So far so good.  I can get things happening when I hover and click the robots.  However when I leave the room and have scenery between the camera and the robots, the hover and click events still get registered.  I understand that this is because the scenery isn't drawn by the ui camera so the clicks and hovers ignore the scenery.

My question is; what is the best way to get my ui to ignore hovers and clicks if there is stuff in the way of the ui objects?

I've had some ideas but was wondering what my more experienced colleagues would do.

Thanks in advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: using scenery to obfuscate ui events?
« Reply #1 on: June 22, 2013, 06:41:51 AM »
UICamera performs a raycast into the scene. Unless there are colliders on your scenery objects to stop this raycast, it will eventually hit your robots, thus resulting in the hover event.

w3iRd c0De

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: using scenery to obfuscate ui events?
« Reply #2 on: June 22, 2013, 06:56:11 AM »
Thanks for the super swift reply!  I thought adding extra colliders to my scenery might be the way to go.  I take it that this method is cheaper at runtime than adding a linecast to the onHover event to check line of sight?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: using scenery to obfuscate ui events?
« Reply #3 on: June 22, 2013, 01:48:15 PM »
NGUI does a Raycast to determine which collider gets hit. I'm not sure what you're asking regarding a linecast (?) and it being cheaper at runtime.

w3iRd c0De

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 3
    • View Profile
Re: using scenery to obfuscate ui events?
« Reply #4 on: June 26, 2013, 02:39:22 AM »
Thanks again for the swift support.  I was thinking about putting a linecast in the OnHover event so that when the robot is hovered over, the script will do a linecast from the robot to the player to see if it hits anything that is not the player.  if it hits the player then the robot is in line of sight and updates the display, otherwise it does nothing.  My hope was I could save adding a bunch of extra colliders to my scene with a couple of lines of code.  After playing with it for the day I think your original suggestion is by far the better one in terms of reliability, so I'm going with that.  Consider my query solved :)