Is it possible to make a reverb zone effect with an audio mixer? Or is there a way to make reerb zones rectangular or polygonal (2D game)?
You could certainly add a reverb effect to a mixer track and control it’s parameters to achieve the effect you want. Have a look at this tutorial if you’re not familiar with audio mixer exposed parameters:
Built-in reverb zones are only spherical/circular, so for any other shape of zone you will have to do some scripting.
using UnityEngine;
using UnityEngine.Audio;
public class RectangularReverbZone : MonoBehaviour
{
public AudioMixer audioMixer;
private Transform playerTransform;
private BoxCollider2D boxCollider;
private void Start()
{
playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
boxCollider = GetComponent<BoxCollider2D>();
}
private void Update()
{
if (playerTransform == null) return; // Exit if there's no player
// If the player is within the box collider
if (boxCollider.bounds.Contains(playerTransform.position))
{
// Calculate distance from the player to the closest edge of the box
float distance = Vector2.Distance(playerTransform.position, boxCollider.ClosestPoint(playerTransform.position));
// Normalize the distance with respect to the box's diagonal (maximum possible distance)
float normalizedDistance = distance / boxCollider.bounds.extents.magnitude;
// Calculate the reverb amount (inversed, because we want more reverb when closer)
float reverbAmount = 1f - normalizedDistance;
// Set the reverb amount in the audio mixer
audioMixer.SetFloat("ReverbAmount", reverbAmount);
}
else
{
// Player is outside the reverb zone, so set reverb amount to 0
audioMixer.SetFloat("ReverbAmount", 0f);
}
}
}