Skip to main content
Up and Coming
May 15, 2025

Amplify Sound

  • May 15, 2025
  • 3 replies
  • 464 views

I am trying to amplify the Meta Avatar's Audiosource using ontriggerenter. Basically I need for everyone in the game to hear the player in that trigger zone throughout the entire world. Can anybody help? I am using one of the Meta Audio Example projects but don't know exactly what to do to accomplish this.

    This topic has been closed for replies.

    3 replies

    Barty98
    Inspiring
    May 15, 2025

    You could add this to your OnTriggerEnter which will make the audio source 2D and play at full volume: 

    audioSource.spatialBlend = 0f

     If you want to keep the audio directional then just tweak the min and max distance of the audio source.

    Up and Coming
    May 15, 2025

    Here is the script. It is meant to pick up the Meta Avatar Voice. Is this correct? Because even when I using the triggerzone and the trigger is checked on the zone it doesn't amplify. Is there something on the editor I need to adjust? 

    using UnityEngine;
    using Normal.Realtime;
     
    public class AutoAmplify : MonoBehaviour
    {
        private RealtimeAvatarVoice _avatarVoice;
        private AudioSource _audioSource;
     
        void Awake()
        {
            _avatarVoice = GetComponentInChildren<RealtimeAvatarVoice>();
            if (_avatarVoice != null)
            {
                _audioSource = _avatarVoice.GetComponent<AudioSource>();
            }
        }
     
        void OnTriggerStay(Collider other)
        {
            if (other.CompareTag("Stage") && _audioSource != null)
            {
                // Store the previous volume for comparison
                float previousVolume = _audioSource.volume;
     
                // Amplify the volume to the maximum
                _audioSource.volume = 1.0f;
                _audioSource.spatialBlend = 0f;
     
                // Log the volume change
                Debug.Log($"AutoAmplify triggered for {other.gameObject.name}. Volume changed from {previousVolume} to {_audioSource.volume}");
            }
        }
     
     
    }
    Barty98
    Inspiring
    May 15, 2025

    Are you getting the debug logs that show the code is actually running? If you want to audio to be louder I believe you will need to use an Audio Mixer.

    Also I believe you want to use OnTriggerEnter instead of OnTriggerStay, then reset your audio settings in OnTriggerExit.