简体   繁体   English

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

[英]How to rotate object smoothly with slider in unity

i am using a slider to rotate my object around its center and its working fine but my object moving so fast even i add speed,the slider value is between 0 and 1,Slider min value is 0 and max 1 and speed is 1, i want to rotate my object smoothly how i can do that please help me thanks here's my code: 我正在使用滑块将对象绕其中心旋转并且工作正常,但是即使我增加速度,我的对象移动也是如此快,滑块的值介于0和1之间,滑块的最小值是0和max 1,速度是1,i想要平稳地旋转对象,我该怎么做,请帮助我,这是我的代码:

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);
    }}

Instead of using .Rotate() function you can just set .rotation property with Quaternion.Euler to rotate your object smoothly using slider. 除了使用.Rotate()函数外,您还可以使用Quaternion.Euler设置.rotation属性,以使用滑块平滑地旋转对象。 Here is a sample code of mine: 这是我的示例代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM