using UnityEngine;
public class Rotation : MonoBehaviour
{
[SerializeField] private float _minAngle = 0;
[SerializeField] private float _maxAngle = 90f;
[SerializeField] private float _speed = 10f;
private float _angle = 0;
private void FixedUpdate()
{
Rotate();
}
private void Rotate()
{
var nextAngle = _angle + _speed * Time.deltaTime;
_angle = Mathf.Clamp(nextAngle, _minAngle, _maxAngle);
transform.rotation = Quaternion.Euler(0, 0, _angle);
if (_angle == _minAngle || _angle == _maxAngle) SwitchDirection();
}
private void SwitchDirection() => _speed *= -1;
}