how to stop a 2d object from rotate in unity code example
Example 1: unity 2d rotate towards direction
private void RotateGameObject(Vector3 target, float RotationSpeed, float offset)
{
Vector3 dir = target - transform.position;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
Quaternion rotation = Quaternion.Euler(new Vector3(0, 0, angle + offset));
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, RotationSpeed * Time.deltaTime);
}
Example 2: rotation unity script 2d
transform.eulerAngles = Vector3.forward * degrees;
transform.rotation = Quaternion.Euler(Vector3.forward * degrees);
transform.rotation = Quaternion.LookRotation(Vector3.forward, yAxisDirection);
transform.LookAt(Vector3.forward, yAxisDirection);
transform.right = xAxisDirection;
transform.up = yAxisDirection;