Version: Unity 6.1 Alpha (6000.1)
LanguageEnglish
  • C#

AudioSource.isPlaying

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public bool isPlaying;

Description

Returns whether the AudioSource is currently playing an AudioResource(Read Only).

AudioSource.isPlaying returns true if the AudioSource is playing any AudioResource, such as AudioClip or AudioRandomContainer. This includes if you use PlayOneShot() or if you play a video or timeline track through the AudioSource.

Note: AudioSource.isPlaying returns false when AudioSource.Pause() is called. If you use AudioSource.Play() back again, it returns true.

Note: If you use AudioSource.PlayDelayed to play your clip, AudioSource.isPlaying returns true during the delay.

// When the audio component has stopped playing, play otherClip.
// Remember to assign an AudioClip in the Inspector.

using UnityEngine; using System.Collections;

public class ExampleClass : MonoBehaviour { public AudioClip otherClip; AudioSource audioSource;

void Start() { audioSource = GetComponent<AudioSource>(); }

void Update() { if (!audioSource.isPlaying) { audioSource.clip = otherClip; audioSource.Play(); } } }