Skip to content

Instantly share code, notes, and snippets.

Created April 28, 2017 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9fb8368a7ca2b3d9d0c4b8f56cd476a4 to your computer and use it in GitHub Desktop.
Save anonymous/9fb8368a7ca2b3d9d0c4b8f56cd476a4 to your computer and use it in GitHub Desktop.
using System.Collections;
public class FadeInWithPanel : MonoBehaviour {
public float fadeInTime;
private Image fadePanel;
private Color currentColor;
public int stayTime = 1;
void Start (){
currentColor = Color.black;
fadePanel = GetComponent<Image> ();
}
void Update (){
if (Time.timeSinceLevelLoad < stayTime) {
currentColor = Color.black;
}
else {
float alphaChange = Time.deltaTime / fadeInTime;
currentColor.a -= alphaChange;
fadePanel.color = currentColor;
} if (Time.timeSinceLevelLoad > fadeInTime + stayTime) {
gameObject.SetActive (false);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment