Subtitles in fps game

Hey guys! I’m making a fps games and I want to have subtitles in it. Like player hits a cube trigger, the the guide subtitle gui comes up at the bottom of the screen, with an audio. The after the audio is done, (example-15 seconds) the gui disappears. Please help, I’m still new to unity, and very, very, very very new to coding.

Thanks!

A simple solution, check out AudioSource.isPlaying. This isn’t a script you can actually use, it’s an example of what you would have inside a C# class, because you didn’t specify which language you prefer. Break down the example and google each part you don’t understand. Also look at the Unity Script Reference that I’ve linked you to with the information on AudioSource.isPlaying.

bool showSubs;
string sub = "This is a subtitle. Audio is Playing.";

void Update()
{
    if(audio.isPlaying)
        showSubs = true;
    else
        showSubs = false;
}

void OnGUI()
{
    if(showSubs)
        GUI.Label(new Rect(0, Screen.height - 64, Screen.width, 64), sub);
}

Create new class inside main class, in that class add string, for subtittle text, one float for start time and second for end time. Set everything public. Then create an array of these classes, without setting constant array size. So now you have a dynamic array, and for each element you can set text, start and end time.

Create ongui function, create a text area or whatever and position the area where the subtitle text will be.

Create a variable wich will hold time for subtitles. Something like a = Time.deltaTime.

Then somehow create a little system wich sends string from array element to ongui function to show it on screen depending on elements start and end time. I would need to draw a diagram on paper and think a bit about it, but I’ll leave something for you ;).