To prevent an audio clip from restarting, perform the following steps:
- Create a new Unity 2D project and import the sound clip file.
- Create a GameObject in the scene containing an AudioSource component that is linked to the engineSound AudioClip. You can do this in a single step by dragging the music clip from the Project panel into either the Hierarchy panel or the Scene panel.
- Uncheck the Play Awake property for the AudioSource component of the engineSound GameObject. This is to ensure the sound does not begin playing as soon as the scene has been loaded.
- Create a UI button named Button-play-sound and change its text to Play Sound. Position the button in the center of the screen by setting its Rect Transform property position to the middle center.
- Create a C# script class, called WaitToFinishBeforePlaying, in a new folder, _Scripts, that contains the following code. Also, add an instance as a scripted component to...