-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathAudioController.cs
33 lines (27 loc) · 1.04 KB
/
AudioController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright (c) Meta Platforms, Inc. and affiliates.
using UnityEngine;
namespace MRMotifs.PassthroughTransitioning
{
public class AudioController : MonoBehaviour
{
[Tooltip("GameObject that contains the renderer with the fader material and usually contains the fader logic.")]
[SerializeField]
private GameObject alphaFader;
[Tooltip("AudioSource that we use to adjust the volume base on the inverted alpha value.")]
[SerializeField]
private AudioSource audioSource;
private Material m_material;
private float m_maxVolume;
private static readonly int s_invertedAlpha = Shader.PropertyToID("_InvertedAlpha");
private void Awake()
{
m_material = alphaFader.GetComponent<Renderer>().material;
m_maxVolume = audioSource.volume;
}
private void Update()
{
var invertedAlpha = m_material.GetFloat(s_invertedAlpha);
audioSource.volume = Mathf.Lerp(m_maxVolume, 0.0f, invertedAlpha);
}
}
}