Question by
forgotten893 · Feb 19, 2018 at 08:03 AM ·
audioscript.audiosource
Trying to make a splitscreen game, having issues with the AudioSource and distance between objects.
So currently Unity doesn't support multiple audio listeners so to work around this I've made all my sounds 2D and I am currently adjusting the volume of the audio source via script, the only problem is, the closer I get to the object, the quieter it gets, instead, I want it so that the closer I get, the louder it gets, any solutions? My code is below.
using UnityEngine;
public class Player : MonoBehaviour
{
private AudioSource audioSource;
private GameObject fireGO;
private void Awake()
{
audioSource = FindObjectOfType<AudioSource>();
fireGO = GameObject.FindGameObjectWithTag("Fire");
}
private void Update()
{
var distance = Vector3.Distance(transform.position, fireGO.transform.position);
audioSource.volume = Mathf.Clamp01(distance / 32.0f);
}
}
Comment