Answers for "how to raycast from gameobject to mouseposition unity2d"

C#
5

raycast from camera to mouse unity

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hit, 100)) {
	Debug.Log(hit.transform.name);
	Debug.Log("hit");
}
Posted by: Guest on July-08-2021
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

C# Answers by Framework

Browse Popular Code Answers by Language