Play layerbased Music/Sound Effects
layerbased means that the audio track is split into multiple files. With the ability to add
/change to
a layer, you can create dynamic music (one good example is Buoy Base Galaxy, the music changes after Mario enters the water)
- Place an Empty GameObject somewhere
- Give this GameObject a
MultiAudioTrack
Component- add Unity's
AudioSource
toAudioSources
(you can add as many as you want) - set starting layer or autoplay if you want
- keep in mind that the first
AudioSource
IS the main audio track (and reference)
- add Unity's
- In a UdonSharp script you can push/pop layers:
using NTF.VRChat;
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
public class SomeUdonSharpScript : UdonSharpBehaviour
{
public MultiAudioTrack track;
void Start()
{
track.PushLayer(); // add the next layer onto the main one
track.PopLayer(); // removes the last layer from the main one
track.PushToggle(); // turns off the current layer and turns on the next layer
track.PushPop(); // turns off the current layer and turns on the previous layer
track.Reference; // this is the main audio track, changing volume, pitch, etc. will affect the other layers too
}
}
Very simple: PushLayer
adds the next layer, PushToggle
plays the next layers and mutes all the others (including the main one!)