unity 2d lock rotation code example

Example 1: unity how to lock rotation

public float lockPos;

	void Update()
	{
		// Locks the rotation.
		transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, lockPos, lockPos);
	}

Example 2: rotation unity script 2d

transform.eulerAngles = Vector3.forward * degrees;
// or
transform.rotation = Quaternion.Euler(Vector3.forward * degrees);
// or
transform.rotation = Quaternion.LookRotation(Vector3.forward, yAxisDirection);
// or
transform.LookAt(Vector3.forward, yAxisDirection);
// or
transform.right = xAxisDirection;
// or
transform.up = yAxisDirection;