Hello Everyone, I am making a music player in unity, i am stuck on a problem…I need to create a Ui slider to control the music track to make it go forward and backward in the same music can anyone please help
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SongStatus : MonoBehaviour
{
public AudioSource animationAudio;
public Slider slider;
bool isPlaying;
void Start()
{
animationAudio.Play();
isPlaying = true;
}
void Update()
{
if (isPlaying)
{
slider.value = animationAudio.time / animationAudio.clip.length;
}
print((int)animationAudio.time);
}
public void SliderDown()
{
animationAudio.Pause();
isPlaying = false;
}
public void SliderUp()
{
if (slider.value * 100 <= animationAudio.clip.length)
{
if (!animationAudio.isPlaying && !isPlaying)
{
animationAudio.time = Mathf.Clamp(slider.value * animationAudio.clip.length, 0f, animationAudio.clip.length);
animationAudio.UnPause();
isPlaying = true;
}
}
else
{
animationAudio.Stop();
slider.value = animationAudio.time;
}
}
}
it may have some errors but atleast you will get an idea from it @murtuu_7723