簡體   English   中英

如何使用滑塊統一平滑地旋轉對象

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

我正在使用滑塊將對象繞其中心旋轉並且工作正常,但是即使我增加速度,我的對象移動也是如此快,滑塊的值介於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);
    }}

除了使用.Rotate()函數外,您還可以使用Quaternion.Euler設置.rotation屬性,以使用滑塊平滑地旋轉對象。 這是我的示例代碼:

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