Easy Fade In

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(EasyFadeIn.cs)
(EasyFadeIn.cs)
Line 9: Line 9:
 
 
 
/*
 
/*
Easy Fade In
+
About
Desi Quintans (CowfaceGames.com), 18 August 2012.
+
Easy Fade In
 +
By Desi Quintans (CowfaceGames.com), 18 August 2012.
 
   
 
   
 
License
 
License

Revision as of 01:44, 18 August 2012

EasyFadeIn.cs

using UnityEngine;
 
[RequireComponent(typeof(AudioSource))]
 
public class EasyFadeIn : MonoBehaviour {
 
	/*
	About
		Easy Fade In
		By Desi Quintans (CowfaceGames.com), 18 August 2012.
 
	License
		Free as in speech, and free as in beer.
 
	Usage
		Attach this script to a GameObject with an AudioSource and enter a fade time. Easy Fade In will
		smoothly increase the audiosource's volume over this period of time until it reaches maximum
		volume, and then will destroy itself to prevent wasting a FixedUpdate() check.
	*/
 
	public int approxSecondsToFade = 10;
 
	void FixedUpdate ()
	{
		if (audio.volume < 1)
		{
			audio.volume = audio.volume + (Time.deltaTime / (approxSecondsToFade + 1));
 
			print (audio.volume);
		}
		else
		{
			Destroy (this);
		}
	}
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox