How to play audio clips stored in multiple different scriptableObjects

Hey everyone,

I’m currently taking a course on Udemy and I am still very new and learning but I went back to one of the first projects I worked on and am trying to add audio to it just for some practice. I can’t figure it out though so I was wondering if anyone could help.

Let me describe how the game works. It’s a very simple text adventure game where it’s all done through the Canvas. The player reads the text, then makes a choice and presses 1 2 or 3 and depending on what they press, different text is loaded from a [SerializedField] from a “State” Scriptable Object into the Canvas replacing the text in the text component and changing where the buttons lead for the next player choice, also drawn from a [SerializedField].

Seeing as how each of these “States” stores the text for the next section, I also thought I could also “[SerializeField] AudioClip stateAudio”, so I did. I set each different audio to each of these “States”.

Problem is… I can’t figure out how to pull the audio from them and play it in the same sort of way that the text does. I’ve spent 4 hours on this, searched everywhere but have only gotten frustrated. I can’t figure out how to play the clips using C#.

I tried to explain things as best I could, hopefully someone will be able to understand what I mean. I can put up pictures too but the project is so simple that I think the above explanation might be enough. Any help would be amazing, thanks!

For example, if you have a audio that says “Hello World How Are you”.
Then using some audio-software ( eg. audacity ) you will have to manually check the timing of each word. For example you get
Hello = 1 ms
World = 2 ms
How = 3 ms
Are = 4 ms
you = 5 ms

Then with this data you can hard code along with the pauses as you want:

audio.time = 1.00f;
audio.Play ();

audio.time = 2.00f;
audio.Play ();

audio.time = 3.00f;
audio.Play ();