Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
rex.gatling.963's avatar
7 months ago

Amplify Sound

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.

3 Replies

Replies have been turned off for this discussion
  • 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.

    • rex.gatling.963's avatar
      rex.gatling.963
      Protege

      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's avatar
        Barty98
        Explorer

        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.