Hi guys,

I was just wondering if anyone could help me with this. I have a campfire within my scene and I would like to produce a script that will procedurally generate fire. I would be using an array of audio clips and would want these to be introduced procedurally. I am really struggling with this and I cannot see any tutorials online anywhere for procedural audio in Unity.

If anyone could help I would be so very grateful.

I am not sure what you are looking for. From what I understand you want to have the ability to play a list of sounds/clips sequentially and possibly even loop them when all sounds have played. Below is a script that will do just that

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class MyAudioManager : MonoBehaviour
{
    [Tooltip("List of AudioClip components. This list must be set to the sounds to be played and in the order of the list.")]
    public List<AudioClip> audioClipList = new List<AudioClip>();

    [Tooltip("The AudioSource component to play the AudioClips.")]
    public AudioSource audioSource;
    
    [Tooltip("AudioSource default. Only used if AudioSource is created at runtime.")]
    public bool loopClips = true;

    [Tooltip("Start playing sound immediately.")]
    public bool playNow = true;

    void Start ()
    {
        // make sure we have a reference to the AudioSource
        if (audioSource == null)
        {
            if (audioSource == null)
            {
                audioSource = gameObject.AddComponent<AudioSource>();
            }
            else
            {
                audioSource = gameObject.GetComponent<AudioSource>();
            }
        }
        audioSource.playOnAwake = false;
        audioSource.loop = false;

        // make sure that alll the AudioClips in the audioClipList are valid by removing any null clips
        audioClipList.RemoveAll(item => item == null);

        if (playNow)
        {
            PlaySequentialSounds();
        }
    }

    public void PlaySequentialSounds()
    {
        StartCoroutine(PlaySounds());
    }

    public void StopSounds()
    {
        StopCoroutine("PlaySounds");
    }

    IEnumerator PlaySounds()
    {
        if (audioClipList.Count > 0)
        {
            for (int i = 0; i < audioClipList.Count; i++)
            {
                audioSource.PlayOneShot(audioClipList*);*

// wait for the lenght of the clip to finish playing
yield return new WaitForSeconds(audioClipList*.length);*
}
}
yield return null;

// if loopClips is set to true then call coroutine
if (loopClips)
{
StartCoroutine(PlaySounds());
}
}
}
If you set the variable loopClips to true (the default) the clips will loop when the last clip has been played.
If you set the variable playNow to true (the default) the clips will start to play immediately on startup.
If you do not want the clips to start playing automatically, you can call PlaySequentialSounds() from another script as it is public. You can also stop sounds at anytime by calling StopSounds(). (Note: You will need a reference to script to call either function PlaySequentialSounds() or StopSounds(). Or if you prefer you can make the class static.
I hope this helps.