public void Update() { if (isUptate) { if (isFadeOut) { time += Time.deltaTime; if (time >= maxTime || !audioManager.IsPlaying()) { isFadeOut = false; time = maxTime; if (clip != null) { audioManager.SetClip(clip); audioManager.play(); } else { audioManager.stop(); } } } else { time -= Time.deltaTime; if (time <= 0) { isUptate = false; time = 0; } } audioManager.SetVolume((maxTime - time) / maxTime); } }
// Update is called once per frame void Update() { if (lastPosition == target.position && music.GetVolume() != 0) { music.SetVolume(0); } else { float sqrMagnitude = (lastPosition - target.position).magnitude; if (sqrMagnitude > maxDistance) { music.SetVolume(1); } else { music.SetVolume(sqrMagnitude / maxDistance); } } lastPosition = target.position; }