Author Topic: How to use NGUI to make a crosshair?  (Read 2933 times)

mapleegreen

  • Guest
How to use NGUI to make a crosshair?
« on: August 21, 2012, 02:03:12 AM »
  1. Ray ray = uiCamera.ScreenPointToRay(uiCamera.WorldToScreenPoint(crossHair.transform.position));
  2.                
  3.                 RaycastHit hit;
  4.                 if(Physics.Raycast(ray.origin,ray.direction,out hit))
  5.                 {
  6.                        
  7.                         string name = hit.transform.root.gameObject.name;
  8.                         Debug.Log("we have hit "+name);
  9.                 }
  10.  
the uiCamera is the NGUI camera,crossHair is the Atlas sprite.Physics.Raycast always failed.Any tip will be grateful.I have been plagued for several days。

PhilipC

  • Guest
Re: How to use NGUI to make a crosshair?
« Reply #1 on: August 21, 2012, 09:21:11 AM »
Could you not just do "Physics.Raycast(crossHair.transform.position, Vector3.forward, out hit)"? Also what are you trying to hit? are these elements in 3D space on a different camera? or are they in 2D space with the same camera?

If they are on different cameras then using the uiCamera to generate the ray would be incorrect (i.e. it would need to be Ray ray = MY3DCAMERA.ScreenPointToRay(uiCamera.WorldToScreenPoint(crossHair.transform.position));)