Created
February 10, 2016 05:13
-
-
Save JackDraak/c5ed2219970e1cd67ef8 to your computer and use it in GitHub Desktop.
fader for Unity
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 UnityEngine.UI; | |
using System.Collections; | |
public class FadePanel : MonoBehaviour { | |
public float fadeInTime= 1f; | |
private Image fadePanel; | |
private Color currentColor = new Color(0f,0f,0f,1f); // or = Color.black; | |
void Start() { | |
fadePanel = GetComponent<Image>(); if (!fadePanel) Debug.LogError (this + " fadePanel IMAGE failure"); | |
} | |
void Update () { | |
if (Time.timeSinceLevelLoad < fadeInTime) { | |
float alphaChange = Time.deltaTime / fadeInTime; | |
currentColor.a -= alphaChange; | |
Debug.Log (this + " Delta: " + alphaChange + " for Alpha result: " + currentColor.a); | |
fadePanel.color = currentColor; | |
} else { | |
gameObject.SetActive(false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FadePanel (FadePanel) Delta: 0.006666666 for Alpha result: 0.9933333
...
FadePanel (FadePanel) Delta: 0.005522184 for Alpha result: 0.4902869
...
FadePanel (FadePanel) Delta: 0.005522385 for Alpha result: -0.001190957