Author Topic: Deselect an object using NGUI's event  (Read 2435 times)

nzen

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 30
    • View Profile
Deselect an object using NGUI's event
« on: December 11, 2012, 10:26:16 PM »
I replaced this code to use NGUI's event system instead:

  1. if (Input.GetMouseButtonDown(0))
  2.                 {
  3.                         Ray ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
  4.                         RaycastHit hit;
  5.  
  6.                         if (Physics.Raycast(ray, out hit, 200f))
  7.                         {
  8.                                 if (hit.transform.gameObject.tag == "PhysicsObj")
  9.                                 {
  10.                                         SelectObject(hit.transform.gameObject); // This is the Event sent.
  11.                                 }
  12.                                 else
  13.                                 {
  14.                                         Deselect();
  15.                                 }
  16.                         }
  17.                         else
  18.                         {
  19.                                 Deselect();
  20.                         }
  21.                 }

Basically, anything outside 200f would do the Deselect, and anything that isn't tagged "PhysicsObj", so I can just click anywhere to deselect things. How do I do this with NGUI events?
« Last Edit: December 12, 2012, 07:14:14 AM by nzen »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Deselect an object using NGUI's event
« Reply #1 on: December 12, 2012, 10:00:51 AM »
UICamera.selectedObject = null;