Author Topic: Raycast problem with existing project  (Read 2288 times)

piotrpo

  • Guest
Raycast problem with existing project
« on: February 09, 2013, 05:11:28 PM »
At the first, hi all.
A have existing problem with raycast used to drag and drop objects.
Code fragment I use to it:
  1.                 if(dragedObject != null && Input.GetMouseButton(0)){
  2.                         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  3.                         if( raycastScreen.collider.Raycast(ray, out hit, 100.0f)){
  4.                                 dragedObject.transform.position = hit.point;
  5.                         }
  6.                 }

How to check if any of buttons was clicked. I want to prevent object moving when user uses one of UI widgets.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Raycast problem with existing project
« Reply #1 on: February 09, 2013, 06:55:53 PM »
1. Don't do raycasts. NGUI already does raycasting for you.
2. UICamera.hoveredObject.

piotrpo

  • Guest
Re: Raycast problem with existing project
« Reply #2 on: February 10, 2013, 02:30:54 PM »
Thanks for help.
2. Works well.
1. What do you mean "don't do raycast"? I'm using it to find and manipulate my own 3D objects (let's assume "touch for shoot somebody"). Anyway I'm not using it for find what GUI button has been clicked. Just have to know if user is using GUI or shooting.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Raycast problem with existing project
« Reply #3 on: February 10, 2013, 10:49:03 PM »
Right, as I said NGUI already does all the raycasts for you. UICamera.hoveredObject gives you 3D objects if your game camera has UICamera attached.