To schedule a sound to play at a certain time, perform the following steps:
- Create a new 2D project and import the audio clip files you wish to use.
- Create a new empty GameObject named SoundManager. Add an AudioSource component that is linked to the Pacman Opening Song AudioClip. You can do this by ensuring the SoundManager GameObject is selected and dragging the clip to either the Hierarchy panel or the Scene panel.
- Uncheck the Play Awake property of the AudioSource component.
- Create a C# script class, called ScheduledSoundManager, that contains the following code. Also, add an instance as a scripted component to the SoundManager GameObject:
using UnityEngine;
using System;
using UnityEngine.UI;
public class ScheduledSoundManager : MonoBehaviour
{
public Text textScheduledMessage;
private AudioSource audioSource;
private bool activated = false;
private float secondsUntilPlay = 0;
private...