Raycasting to find mouseclick on Object in unity 2d games

149

Raycasting to find mouseclick on Object in unity 2d games -

RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);

if(hit.collider != null)
{
    Debug.Log ("Target Position: " + hit.collider.gameObject.transform.position);
}

Comments

Submit
0 Comments