Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

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);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Raycasting #find #mouseclick #Object #unity #games
ADD COMMENT
Topic
Name
6+3 =