Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: shokinhan on August 17, 2013, 08:42:31 AM
-
If use the raycasts ,and last frame click a UIwidget , if you click sence and the lasthit will be changed!
So the lasthit is error.
Because the code "if(hits.Length > 1) else if(hits.Length == 1 && IsVisible(ref hits[0]))", the another case not be processed!
// If raycasts should be clipped by panels, we need to find a panel for each hit
if (cam.clipRaycasts)
{
RaycastHit[] hits = Physics.RaycastAll(ray, dist, mask);
if (hits.Length > 1)
{
System.Array.Sort(hits, delegate(RaycastHit r1, RaycastHit r2) { return r1.distance.CompareTo(r2.distance); });
for (int b = 0, bmax = hits.Length; b < bmax; ++b)
{
if (IsVisible(ref hits))
{
hit = hits;
return true;
}
}
}
else if (hits.Length == 1 && IsVisible(ref hits[0]))
{
hit = hits[0];
return true;
}
// another ? How to do?
// If you don't do hit= somevalue, the hit are old. It will make some bu on next frame!
continue;
-
Set hit = new RaycastHit(); at the top of the function. Not sure why this causes an issue for you though, your post is not very clear. The function returns a 'false' if nothing was hit.
-
Because I use the UICamera.lastHit for judge the mouse whether above on UI or the Sence.
So the lasthit is not null ,then the result about the function CheckMouse always is "Above on UI".
My code such as:
void CheckMouse()
{
Collider collider = UICamera.lastHit.collider;
if (collider != null)
{
if (_GetWidget(collider.gameObject) != null)
{
debug("The Mouse Is Above On UI");
}
else
{
debug("The Mouse has Left UI");
}
}
else
{
debug("The Mouse has Left UI");
}
}
-
You shouldn't be using that. UICamera.hoveredObject tells you whether you're over the UI or not.
-
I will try do it again.
Thanks very much!
-
I think if the var UICamera.lastHit's maybe is old and if you don't allow user use the var, you should set the var private.
-
LastHit is not supposed to be private. Using lastHit is how you determine additional info about the raycast. It's intended to be public.