This is probably something common, but I can’t figure out what’s causing it. I’ve looked around but not really match my situation.
Basically I’ve populated an array full of sound clips that depending on a value are played. The problem I have is that I can’t hear them. The audio holder is attached to an object near the player, and the play on awake box is ticked. The audio listener on the camera is on. The script works setting a new clip each time the value changes. I just don’t hear anything.
Any ideas? Also I can post the script if needed.
Sound like you’ve got everything set up. We could help you more if you post relevant code.
[Edit]
Reading it again, are you calling Play() on your audio source after switching clips?
KyleOlsen:
Sound like you’ve got everything set up. We could help you more if you post relevant code.
[Edit]
Reading it again, are you calling Play() on your audio source after switching clips?
No…I didn’t even realize that had to be done. Posting code.
public AudioClip[] trailers;
public AudioSource audioHolder;
public float tex_offset;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
tex_offset = this.renderer.material.GetTextureOffset("_MainTex").x;
if(tex_offset <= 0.25f)
{
audioHolder.clip = trailers[0];
}
if(tex_offset >= 0.25f tex_offset < 0.50f)
{
audioHolder.clip = trailers[1];
}
if(tex_offset >= 0.50f tex_offset < 0.75f)
{
audioHolder.clip = trailers[2];
}
if(tex_offset >= 0.75f tex_offset < 1f)
{
audioHolder.clip = trailers[3];
}
}
Yep, looks like setting an AudioSource’s clip will stop play. This is working for me:
public AudioClip[] trailers;
public AudioSource audioHolder;
public float tex_offset;
void Start()
{
if (audioHolder != null)
{
audioHolder.loop = true;
}
}
void Update()
{
tex_offset = this.renderer.material.GetTextureOffset("_MainTex").x;
if (tex_offset <= 0.25f)
{
audioHolder.clip = trailers[0];
}
if (tex_offset >= 0.25f tex_offset < 0.50f)
{
audioHolder.clip = trailers[1];
}
if (tex_offset >= 0.50f tex_offset < 0.75f)
{
audioHolder.clip = trailers[2];
}
if (tex_offset >= 0.75f tex_offset < 1f)
{
audioHolder.clip = trailers[3];
}
if (audioHolder.isPlaying == false)
audioHolder.Play();
}