CodeBlanks Logo Icon CodeBlanks

Play and Stop

Learn to play sound with audioSource.Play and stop with Stop.

Audio control with Play and Stop

To start playing the clip linked to an AudioSource, call Play(), and to terminate playback completely, call Stop().

AudioSource source = GetComponent<AudioSource>();
// Starting and stopping playback
source.Play();
source.Stop();

Whether audio is currently running can be queried through the source.isPlaying boolean property.

Using Pause and PlayOneShot

To pause playback at its current timestamp, call Pause(), and resume it using UnPause(). To trigger a one-time sound over existing audio without interrupting it, use PlayOneShot(clip).

// Playing coin collect sound over background music
source.PlayOneShot(coinClip);

PlayOneShot can overlay multiple projectile or impact sounds simultaneously over a single AudioSource.

Practice Print playback action and state

Assign "Play" to action and "Playing" to state. Print Action: Play | State: Playing to the console.

Starter code

Player.cs
using System;

class Program
{
    static void Main()
    {
        // action ve state değerlerini tanımlayıp yazdır
    }
}

Sample solution

Player.cs
using System;

class Program
{
    static void Main()
    {
        string action = "Play";
        string state = "Playing";
        Console.WriteLine("Action: " + action + " | State: " + state);
    }
}

Expected output

Action: Play | State: Playing

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which property on an AudioSource checks whether audio is currently playing actively?

  • isSilent
  • isAudible
  • isPlaying Correct answer
  • isLooping

Explanation: isPlaying is the state property returning true as long as the AudioSource is currently producing sound.

2 Play one shot sound

Question
audioSource.____(hitClip);
Answer
audioSource.PlayOneShot(hitClip);

Explanation: PlayOneShot is used to play a one-time sound clip without interrupting existing audio.

3 Playback controls

Term Meaning
Play() Method playing audio from beginning
Stop() Method stopping audio and resetting
Pause() Method pausing audio at current point
PlayOneShot() Method layering a one-shot sound clip

All lessons in Intermediate