我有一个音频剪辑和一个滑块。滑块充当音频剪辑的进度条(时间线)。我可以暂停和播放音频,也可以跳过曲目。一切正常。问题是滑块移动不顺畅,有点紧张。如果有人可以,请编辑它。提前致谢。
这是代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MusicPlayer : MonoBehaviour
{
AudioSource audioSource;
Slider slider;
public AudioClip track;
// Start is called before the first frame update
void Start()
{
audioSource = GetComponent<AudioSource>();
slider = GetComponent<Slider>();
audioSource.clip = track;
audioSource.Play();
slider.minValue = 0;
slider.maxValue = track.length;
}
// Update is called once per frame
void Update()
{
slider.value = audioSource.time;
}
public void MovePoition()
{
audioSource.time = slider.value;
}
public void play()
{
audioSource.Play();
}
public void pause()
{
audioSource.Pause();
}
}