📅  最后修改于: 2022-03-11 14:49:14.284000             🧑  作者: Mango
// Do not use "transform.LookAt" for 2D
// Instand use something similar to this
public static void LookAt2D(this Transform transform, Vector2 target)
{
var direction = target - (Vector2)transform.position; // Get the direction
var angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; // Convert to angle
transform.rotation = Quaternion.AngleAxis(angle - 90, Vector3.forward); // Finally rotate the GameObject
}