Local Music Toggle
Toggle an audio source on and off locally for each player.
Category: Audio Systems
UdonSharp Script
using UdonSharp;
using UnityEngine;
using VRC.Udon;
public class LocalMusicToggle : UdonSharpBehaviour
{
public AudioSource musicSource;
public override void Interact()
{
if (musicSource == null) return;
if (musicSource.isPlaying)
{
musicSource.Stop();
}
else
{
musicSource.Play();
}
}
}
Setup
- Add script to an interactable button.
- Assign
musicSource. - Add
VRC_Interactableto the same object.
Notes
- This is local-only by design.
- Use synced state if you want shared music control.
Extra Tips and Troubleshooting
Tips and Tricks
- Default music to off in quiet worlds and let players opt in.
- Keep toggle near related audio zone signage.
Troubleshooting
- If no sound plays, check AudioSource clip, volume, and spatial blend settings.
Related Content
Prefab Setup Notes
Import the prefab or script into a throwaway test scene before adding it to a live world. Confirm inspector references, ownership behavior, sync, triggers, UI hooks, and audio or object links before moving it into the production scene.
Testing Checklist
- Test once as a local player and again with a second client or late joiner if the behavior can affect more than one player.
- Confirm ownership, sync, trigger zones, UI references, and audio or object references are assigned intentionally.
- Check desktop and VR interaction distance so players can actually use the feature in context.
- Keep a backup of the scene before changing prefabs, UdonBehaviours, or serialized references.
