通过滑动条控制Cube旋转
private float speed = 10;
private float speedValue;
private GameObject slider;
private GameObject cubeObj;
void Start()
{
slider = GameObject.Find("Canvas/Slider");
cubeObj = GameObject.Find("Cube");
slider.GetComponent<Slider>().onValueChanged.AddListener(delegate
{
speedValue = slider.GetComponent<Slider>().value;
speed = speedValue;
});
}
void Update ()
{
cubeObj.transform.Rotate(Vector3.up * Time.deltaTime * speed);
}