InAudio Documentation

Advanced Audio Plugin for Unity

User Tools

Site Tools


examples:playusingeventviacode

Play a sound using event hook

Open the Audio & Event window from Window/InAudio in the Unity toolbar.

Create audio

To play a sound drag a clip from the project to the audio window.

Create event

Create an event to play the sound from the Event Window. Instead of dragging, you can also right click on the audio definition and press “Send to event window” and skip the next step.

Drag that the newly created audio node onto the event and a play action will be created.

Add the event trigger

Instead of using the event hook, you can use your own code. Create a script and add the following code or add the appropriate elements to your own script.

using UnityEngine;

public class PlayEventExample : MonoBehaviour
{
    public InAudioEvent eventExample;

    void OnEnable()
    {
        //Post the event and thus play the audio attached to this game object.
        //Moving the game object will move the sound as well.
        InAudio.PostEvent(gameObject, eventExample);
    }
}

Add the Audio Event Hook script to a gameobject and drag the event to any of the drop points.

Drag your event to the inspector


Press play and hear the sound play as the object is enabled!

examples/playusingeventviacode.txt · Last modified: 2015/07/12 09:40 by peterolsted