Author Topic: Bug about the UICamera's clipRaycasts?  (Read 3545 times)

shokinhan

  • Guest
Bug about the UICamera's clipRaycasts?
« 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;










ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug about the UICamera's clipRaycasts?
« Reply #1 on: August 18, 2013, 07:50:26 AM »
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.

shokinhan

  • Guest
Re: Bug about the UICamera's clipRaycasts?
« Reply #2 on: August 18, 2013, 08:25:30 AM »

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");
      }
}

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug about the UICamera's clipRaycasts?
« Reply #3 on: August 18, 2013, 08:29:28 AM »
You shouldn't be using that. UICamera.hoveredObject tells you whether you're over the UI or not.

shokinhan

  • Guest
Re: Bug about the UICamera's clipRaycasts?
« Reply #4 on: August 18, 2013, 08:49:53 AM »
I will try do it again.

Thanks very much!

shokinhan

  • Guest
Re: Bug about the UICamera's clipRaycasts?
« Reply #5 on: August 18, 2013, 08:54:55 AM »
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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Bug about the UICamera's clipRaycasts?
« Reply #6 on: August 18, 2013, 02:47:56 PM »
LastHit is not supposed to be private. Using lastHit is how you determine additional info about the raycast. It's intended to be public.