Created
November 11, 2013 21:47
-
-
Save jakevsrobots/7421023 to your computer and use it in GitHub Desktop.
Example script to fade in an audio player when entering a trigger. There should be an AudioSource component also attached to this game object, and it should probably be in "loop" mode.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class TriggerSound : MonoBehaviour { | |
float targetVolume = 0; | |
void Start() { | |
audio.Play(); | |
} | |
void Update() { | |
audio.pitch = Mathf.MoveTowards(audio.volume, targetVolume, | |
Time.deltaTime); | |
} | |
void OnTriggerEnter() { | |
targetVolume = 1; | |
} | |
void OnTriggerExit() { | |
targetVolume = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment