Hello,
I would like to know how I can click on an object during game play and to find out what object was clicked?
I mean without adding an script for each single object in the scene.
Any suggestions?
and I’m new to Unity. :lol:
Hello,
I would like to know how I can click on an object during game play and to find out what object was clicked?
I mean without adding an script for each single object in the scene.
Any suggestions?
and I’m new to Unity. :lol:
Attach colliders to your objects and do a raycast:
thank you, I’ll try it.
Once again it worked perfectly, JUST the way I wanted.
public class InfoOnMouseObject : MonoBehaviour
{
void Update()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray,out hit, 100f))
{
print(hit.collider.gameObject.name);
Debug.DrawLine(ray.origin, hit.point);
}
}
}