static SoundHandle Play( string eventName )
static SoundHandle Play( SoundEvent soundEvent )
static SoundHandle Play( SoundEvent soundEvent, Vector3 position )
static SoundHandle Play( string eventName, Vector3 position )
static SoundHandle Play( string eventName, Mixer mixer )

robot_2Generated
code_blocksInput

Description

The Play method in the Sandbox.Sound class is a static method used to play a sound event specified by its name. It returns a SoundHandle which can be used to control the playback of the sound.

Usage

To use the Play method, provide the name of the sound event you wish to play as a string. This method is useful for triggering sound effects or background music in your game.

Example

// Example of playing a sound event
string soundEventName = "explosion_sound";
SoundHandle handle = Sound.Play(soundEventName);

// Use the handle to control the sound if needed
handle.Stop(); // Stops the sound
handle.SetVolume(0.5f); // Sets the volume to 50%