Easy Fade In

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page.)
 
(EasyFadeIn.cs)
Line 9: Line 9:
 
 
 
/*
 
/*
Easy Fade In
+
Easy Fade In
By Desi Quintans (CowfaceGames.com), 18 Aug 2012.
+
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
 
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
 
smoothly increase the audiosource's volume over this period of time until it reaches maximum

Revision as of 01:43, 18 August 2012

EasyFadeIn.cs

using UnityEngine;
 
[RequireComponent(typeof(AudioSource))]
 
public class EasyFadeIn : MonoBehaviour {
 
	/*
	Easy Fade In
		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