NGUI and raycast hit point

I’m trying to create a script to move my character to a point on the terrain that works with NGUI because currently I am using a script along with NGUI and it is causing me issues.

	void rayCastClick()
	{
		if (Input.GetButtonDown("Mouse0"))
		{
			
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			RaycastHit hit;
				
			if(Physics.Raycast(ray, out hit, 100))
			{
			
				if(hit.collider.gameObject.tag == "Terrain")
				{
					//Take hit point and move to hit position on terrain
				}
			}
		}
	}
}

Can anyone give me an example of how I would do this using NGUI’s event system? I’m not sure how to do it.

NGUI uses raycasts but your raycasts are not affecting it - it doesn’t work like that. I would leave it alone as @iwaldrop says because your UI should be on a different layer to everything else (and your UI should normally be positioned away from your scene).

If you do want to access the last thing hit by NGUI it’s in:

      UICamera.lastHit

You have to attach the UICamera script to your main camera object (the one that shows the terrain)and set the Event type to UI/World (I can’t remember which one, but I guess it is World). That way, objects shown by that camera will also generate the NGUI events.

You should set for NGUI’s camera is MainCamera tag.

May be you can use this

static bool UICamera.IsPressed (
GameObject go)