a noob here so please pardon me if my question is extremely noob.
I'm trying to make an AudioSlider within my Unity program. Currently, the code that I'm using does not make the slider slide with the WAV and returns a NullReferenceException (Object reference not set to an instance of an object).
This is my code:
using UnityEngine;
using UnityEngine.UI;
public class TimeBar : MonoBehaviour
{
[SerializeField]
private AudioSource source;
private Slider timeBar;
public void UpdateSourceTime(float value)
{
source.time = value;
}
private void OnEnable()
{
timeBar = GetComponent<Slider>();
}
void Start()
{
timeBar.maxValue = source.clip.length;
}
}
Can't seem to find a tutorial showing how to do an audio scrubber, most are volume sliders so I'm not very sure how to proceed or what to research on.
Below is the code that worked perfectly. Please change the code and check each item.
In the following, everything is attached to the Slider for ease of explanation, but it does not matter if it is attached to a different object.