由于项目现场测试出现问题,小编不得不用unity自带的视频播放器组件,在网上找了很多代码,但是大致都是一样的,小编觉得网上的代码有点长,就自己写了一个简单的代码用来实现滚动条播放和控制,代码不多,就几行,不过可以满足需要的功能,希望对大家有帮助
如果有问题请进群联系我unity开发群 636926481
public VideoPlayer player;
public Slider slider;
bool switch_bool = true;
void Start () {
slider.onValueChanged.AddListener((float value) => SliderEvent(value));
}
void Update () {
if (switch_bool)
{
slider.value = (float.Parse(player.frame.ToString() ) / float.Parse(player.frameCount.ToString()));
}
}
public void PointerDown()
{
switch_bool = false;
}
public void PointerUp()
{
switch_bool = true;
}
public void SliderEvent(float value)
{
player.frame = long.Parse((value * player.frameCount).ToString("0."));
}
或者
public s