unity3d滑块的移动手柄
moving handle of unity3d slider
我正在做一个 unity3d 4.7.0f1
项目,希望滑块的手柄从 min
值左右移动到 max
值并返回,直到我单击按钮。
最好的方法是什么?
这是将滑块值设置在 0 到最大值之间的示例脚本(Mathf.PingPong 期望最小值为 0)。您可以检查分配按钮单击以禁用此脚本(因此更新循环停止 运行)
附加到空游戏对象,将 Slider 分配给它,测试。
using UnityEngine;
using UnityEngine.UI;
public class SliderPingPong : MonoBehaviour
{
public Slider slider;
public float speed = 1;
float pos = 0;
void Update()
{
pos += speed * Time.deltaTime;
slider.value = Mathf.PingPong(pos, slider.maxValue);
}
}
要点中的相同脚本源:
https://gist.github.com/unitycoder/a69c4ff5324336cfa33bde23c09d7397
slider.SetValueWithoutNotify
可用于避免触发 value-update 回调。
我正在做一个 unity3d 4.7.0f1
项目,希望滑块的手柄从 min
值左右移动到 max
值并返回,直到我单击按钮。
最好的方法是什么?
这是将滑块值设置在 0 到最大值之间的示例脚本(Mathf.PingPong 期望最小值为 0)。您可以检查分配按钮单击以禁用此脚本(因此更新循环停止 运行)
附加到空游戏对象,将 Slider 分配给它,测试。
using UnityEngine;
using UnityEngine.UI;
public class SliderPingPong : MonoBehaviour
{
public Slider slider;
public float speed = 1;
float pos = 0;
void Update()
{
pos += speed * Time.deltaTime;
slider.value = Mathf.PingPong(pos, slider.maxValue);
}
}
要点中的相同脚本源: https://gist.github.com/unitycoder/a69c4ff5324336cfa33bde23c09d7397
slider.SetValueWithoutNotify
可用于避免触发 value-update 回调。