Horje
Unity Make a 2D object look at the mouse position Code Example
unity 2d how to set an object or the mouse position
    Vector2 mousePos = new Vector2(camera.ScreenToWorldPoint(Input.mousePosition.x), camera.ScreenToWorldPoint(Input.mousePosition.y));        
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);
    }
}




Csharp

Related
unity get distance between two objects Code Example unity get distance between two objects Code Example
unity check if key pressed Code Example unity check if key pressed Code Example
rigidbody2d freeze position Code Example rigidbody2d freeze position Code Example
unity textmesh pro Code Example unity textmesh pro Code Example
wpf numeric only textbox Code Example wpf numeric only textbox Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11