SoundHandle PlaySound( SoundEvent sound, Vector3 positionOffset )

robot_2Generated
code_blocksInput

Description

The PlaySound method plays a specified sound on the GameObject. The sound will follow the position of the GameObject as it moves. This method is useful for adding audio effects that are spatially aware, enhancing the immersive experience in a scene.

Usage

To use the PlaySound method, you need to have a SoundEvent that defines the sound you want to play. You can also specify a Vector3 position offset if you want the sound to originate from a point relative to the GameObject's position.

Here is how you can call the method:

SoundEvent mySound = new SoundEvent("path/to/sound");
Vector3 offset = new Vector3(0, 0, 0); // No offset
SoundHandle handle = myGameObject.PlaySound(mySound, offset);

The method returns a SoundHandle which can be used to control the sound playback, such as stopping or pausing the sound.

Example

// Example of using PlaySound method
GameObject myGameObject = new GameObject();
SoundEvent mySound = new SoundEvent("sounds/explosion.wav");
Vector3 positionOffset = new Vector3(1.0f, 0.0f, 0.0f); // Offset the sound to the right

// Play the sound with the specified offset
SoundHandle soundHandle = myGameObject.PlaySound(mySound, positionOffset);

// Optionally, you can use the soundHandle to control the sound
// soundHandle.Stop(); // Stops the sound
// soundHandle.Pause(); // Pauses the sound