Answers for "detect all gameobjects clicked by mouse unity 2d"

C#
0

Unity Make a 2D object look at the mouse position

public class LookAtMouse : MonoBehaviour
{
    void Update()
    {
        Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        
        Vector2 direction = mousePosition - transform.position;
        float angle = Vector2.SignedAngle(Vector2.right, direction);
        transform.eulerAngles = new Vector3 (0, 0, angle);
    }
}
Posted by: Guest on October-01-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

Code answers related to "detect all gameobjects clicked by mouse unity 2d"

C# Answers by Framework

Browse Popular Code Answers by Language