5月25日
计划制作一个旋转的方块,用滑块控制旋转速度,用按钮控制开始停止
首先简单实现小球旋转部分函数
public bool isRo = true;
public float speed = 10;
public float x = 0;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (isRo)
{
x += Time.deltaTime * speed;
transform.rotation = Quaternion.Euler(0, 0, x);
}
}
编写开始和停止函数,将其挂载到按钮上
public void changeRo()
{
if (isRo == true)
{
isRo = false;
}
else
{
isRo = true;
}
}
创建一个滑块,并编写速度控制函数,将函数挂载在滑块上
注意:一定要选择dynam float下的函数,才能让滑块正确控制速度
public void changeSpeed(float x)
{
speed = x*100;
}