如何在统一中使用滑块平滑地旋转对象

How to rotate object smoothly with slider in unity

我正在使用滑块围绕其中心旋转我的对象并且它工作正常但是我的对象移动得如此之快即使我增加速度,滑块值在 0 和 1 之间,滑块最小值是 0 和最大值 1 和速度是 1,我想平稳地旋转我的物体我该怎么做请帮助我谢谢 这是我的代码:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class RotateObject : MonoBehaviour {
public float speed =1f;
public GameObject ObjectToRotate;

public void RotateMyObject()
    {
    float sliderValue = GetComponent<Slider>().value;
    ObjectToRotate.transform.Rotate(sliderValue*speed*Time.deltaTime,0,90);
    }}

而不是使用 .Rotate() 函数,您只需设置 .rotation 属性 和 Quaternion.Euler 即可使用滑块平滑地旋转对象。这是我的示例代码:

public void RotateMyObject()
{
    float sliderValue = GetComponent<Slider>().value;
    ObjectToRotate.transform.rotation = Quaternion.Euler(sliderValue * 360, 0, 90);
}