目前想实现slider进行物体的旋转,往右最多可以转180度,往左也是最多转-180度,中间为零,但是现在遇到问题是,我往右拉到底后,我的物体会一直旋转不会停,角度也会一直乱跳,往左也一样,请问该怎么进行修改?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
public class NewBehaviourScript : MonoBehaviour
{
public float rotationMin = -180f;
public float rotationMax = 180f;
public Slider RotateSlider;
[SerializeField] float currentRotation = 0f;
// Start is called before the first frame update
void Start()
{
RotateSlider = GameObject.Find("RotateSlider").GetComponent<Slider>();
}
// Update is called once per frame
void Update()
{
transform.Rotate(new Vector3(0f, 0f, RotateSlider.value), Space.Self);
}
private void OnGUI()
{
//currentRotation = OnGUI.HorizontalSlider(new Rect(-280f, 165.0f, 228.0f, 57.0f), currentRotation, 0.0f, 45.0f);
transform.Rotate(new Vector3(0f, 0f, currentRotation), Space.Self);
}
public void AdjustAngle(float newAngle)
{ }
}
求各位指导一下,顺便看看程式哪里有问题,感谢了!