Look At Mouse in 2D Game

Make game object look  at mouse position in 2d games more complex then 3d games , so in this tutorial i show you my way that i use for my games.

watch video tutorial and copy past that code :

using UnityEngine;

public class LookAtMouse : MonoBehaviour

void Update()
    var pos = Camera.main.WorldToScreenPoint(transform.position);
    var dir = Input.mousePosition - pos;
    var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
    transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);