Answers for "Raycasting to find mouseclick on Object in unity 2d games"

0

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);
}
Posted by: Guest on July-01-2021

Browse Popular Code Answers by Language