using UnityEngine; public class RotateAngle2D : MonoBehaviour { public float angle1 = -0.7f; public float angle2 = 0.7f; public float speed = 0.7f; float angle; bool right = true; void Start() { angle = transform.rotation.z; } void FixedUpdate() { if (right == true) { transform.Rotate(new Vector3(0f, 0f, 1f) * speed); } else { transform.Rotate(new Vector3(0f, 0f, -1f) * speed); } if (transform.rotation.z >= angle2 || transform.rotation.z <= angle1) { right = !right; } } }