I’m making a top down RTS style game and I’m trying to get troop selection to work through shooting a raycast from the camera to where the mouse is. I’m doing this in 2D and what I want it to o is shoot a raycast and return the name of the gameobject but it doesn’t. Please help.
void update()
{
if (Input.GetMouseButtonDown(0))
{
Select();
}
}
void Select ()
{
RaycastHit2D Selectinfo = Physics2D.Raycast(Camera.main, Input.mousePosition);
if (Selectinfo)
{
Debug.Log(Selectinfo.transform.name);
}
}