Vector2 directionToPlayer = playerPosition - transform.position; Vector2 normalizedDirection = directionToPlayer.Normalize();
Vector2 normalizedVector1 = vector1.Normalize(); Vector2 normalizedVector2 = vector2.Normalize(); float cosineOfAngle = Vector2.Dot(normalizedVector1, normalizedVector2);This function is part of the UnityEngine package library which is included with Unity.