Concept Flow - Playing sound effects
Start
Load AudioClip
Get AudioSource
Call PlayOneShot()
Sound plays
End
This flow shows how Unity plays a sound effect by loading the sound, getting the AudioSource, and then playing it.
AudioSource audioSource;
AudioClip clip;
void PlaySound() {
audioSource.PlayOneShot(clip);
}| Step | Action | AudioSource State | Sound Played | Output |
|---|---|---|---|---|
| 1 | AudioSource and AudioClip assigned | assigned AudioSource, clip loaded | No | No sound yet |
| 2 | PlaySound() called | playing sound | Yes | Sound effect starts playing |
| 3 | Sound plays fully | playing sound | Yes | Sound effect ends |
| 4 | End of PlaySound() | audioSource ready | No | Ready for next sound |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|---|
| audioSource | null | assigned AudioSource | playing sound | playing sound | ready |
| clip | null | assigned AudioClip | assigned AudioClip | assigned AudioClip | assigned AudioClip |
Playing sound effects in Unity: - Get an AudioSource and load an AudioClip - Use audioSource.PlayOneShot(clip) to play sound once - Multiple PlayOneShot calls can overlap sounds - AudioClip must be assigned or no sound plays - AudioSource remains ready after playing