private float rotateSpeed = 0;
private int maxSpeed = 1500;
private bool speedUp = false; //旋转状态,加速,减速
// Start is called before the first frame update
void Start()
{
InvokeRepeating("AdjustSpeed", 0.1f, 0.1f);
}
// Update is called once per frame
void Update()
{
//旋转、rotateSpeed 用来控制转速
gameObject.transform.Rotate(0, rotateSpeed * Time.deltaTime, 0, Space.Self);
//点一下,加速,再点一下,减速
if (Input.GetMouseButtonDown(0))
{
speedUp = !speedUp;
}
}
private void AdjustSpeed()
{
if (speedUp)
{
if (rotateSpeed < maxSpeed)
{
rotateSpeed += 10;
}
}
else
{
rotateSpeed -= 10;
rotateSpeed = rotateSpeed < 0 ? 0 : rotateSpeed;
}
}