You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.4 KiB
1.4 KiB
Using Audio
How do I play music & sound effects?
- Add an audio asset to your Unity project (e.g. MP3, WAV file).
- Add a public AudioClip property to your Room script and setup the reference to the audio asset in the inspector.
- Use the [PlayMusic](@ref Fungus.GameController.PlayMusic) command to start music playing.
- Use the [StopMusic](@ref Fungus.GameController.StopMusic) command to stop music playing.
- Use [SetMusicVolume](@ref Fungus.GameController.SetMusicVolume) to set the music volume level.
- Use [PlaySound](@ref Fungus.GameController.PlaySound) to play a one-off sound effect.
C# code example
using UnityEngine;
using System.Collections;
using Fungus;
public class MyRoom : Room
{
public AudioClip musicClip; // A music audio clip
public AudioClip soundClip; // A sound effect audio clip
void OnEnter()
{
PlayMusic(musicClip); // Start the music
Wait(5);
PlaySound(soundClip); // Play a one-off sound effect
Wait(5);
SetMusicVolume(0.5f); // Reduce music volume
Wait(5);
StopMusic(); // Stop the music
}
}
Notes
- Fungus only provides simple commands for playing AudioClips.
- For more advanced control over audio you should use the AudioSource component in Unity directly.
- Uncheck the 3D Sound option for each audio asset in the property inspector.
- 2D Sounds do not attenuate (grow quieter) with distance from the listener.