SoundHandle PlaySound( SoundEvent sound, Vector3 positionOffset )

robot_2Generated
code_blocksInput

Description

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.

Example usage:

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

Example

// Example of using PlaySound on a GameObject
SoundEvent mySound = new SoundEvent("sounds/explosion");
Vector3 positionOffset = new Vector3(1.0f, 0.0f, 0.0f);
SoundHandle soundHandle = myGameObject.PlaySound(mySound, positionOffset);

// The sound will play at the GameObject's position with the specified offset.