Ejemplo n.º 1
0
    /// <summary>
    /// Creates an audio instance.
    /// </summary>
    /// <param name="position">Position of the sound.</param>
    /// <param name="volume">The volume, this defines the importance and scale of the sound.</param>
    public void EmitAudio(Vector3 position, float volume)
    {
        AudioInstanceScript inst = Instantiate(_audioPrefab).GetComponent <AudioInstanceScript>();

        inst.transform.position = position;
        inst.Volume             = volume;
    }
Ejemplo n.º 2
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("AudioInstance"))
     {
         AudioInstanceScript inst = other.GetComponent <AudioInstanceScript>();
         if (!_soundsInRange.Contains(inst))
         {
             _soundsInRange.Add(inst);
         }
     }
 }
Ejemplo n.º 3
0
    /// <summary>
    /// Returns the position of the loudest sound in range, preferring the last sound emitted.
    /// </summary>
    /// <returns></returns>
    public Vector3 GetSoundPosition()
    {
        AudioInstanceScript toReturn = null;

        foreach (AudioInstanceScript sound in _soundsInRange)
        {
            if (!toReturn)
            {
                toReturn = sound;
            }
            else if (toReturn && toReturn.Volume <= sound.Volume)
            {
                toReturn = sound;
            }
        }
        return(toReturn.transform.position);
    }