D
D
Dmitry2016-11-13 04:10:05
Unity
Dmitry, 2016-11-13 04:10:05

How to properly Raycast in the editor window?

Hello dear experts.
I'm making a stray in my custom inspector that would display data (detailed information) on the object over which the mouse cursor is currently located in the scene editor window. The objects are all 2D sprites.
I have compiled the following code, but it does not work for me:

Ray ray =  Camera.main.ScreenPointToRay (Event.current.mousePosition );
Debug.Log(ray);

RaycastHit hit;
// Shoot this ray. check in a distance of 10000.
if (Physics.Raycast(ray, out hit, 10000))
{			
  Debug.Log ("Raycast hit name: " + hit.collider.gameObject.name);
}

Can you tell me where I got the error?
Or did I start digging in the wrong direction?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question