Play audio clip

Hi i need help i am new to unity and coding and i dont know how do i make sound to play
i am making quiz game and here is the script

public void UserSelectTrue()
{
animator.SetTrigger(“True”);
if (currentQuestion.isTrue)
{
Debug.Log(“CORRECT!”);
}
else
{
Debug.Log(“WRONG”);
}

    StartCoroutine(TransitionToNextQuestion());
}

I need help like when that code plays it plays the sound

sorry for bad english i am from finland

Thank you for helping :slight_smile:

1 Answer

1

Add an AudioSource component to the GameObject. Drop in a sound file to the AudioClip property.

In script, instruct the AudioSource to play.

 public AudioSource audioSource;
 ....
 audioSource.Play();

https://unity3d.com/learn/tutorials/topics/audio

https://docs.unity3d.com/ScriptReference/AudioSource.Play.html

https://docs.unity3d.com/Manual/Audio.html

http://answers.unity3d.com/search.html?f=&type=question&redirect=search%2Fsearch&sort=relevance&q=play+sound