I’m trying to get a fade out then in on the alpha. Can’t seem to get it. Player will teleport, during the switch screen fades out then in. This is my code but it just fades out… I’m pretty new at this so detailed explanations are appreciated! I have a feeling it has something to do with Mathf.Sin?
void Update () {
panel.GetComponent<Image> ().color = new Color(0,0,0,alpha);
if (alphaTog <= 0) {
alpha += fadeSpeed * Time.deltaTime;
if (alpha == 255f) {
alphaTog = 1;
}
} else if(alphaTog == 1){
alpha -= fadeSpeed * Time.deltaTime;
}
Try this:
void Update () {
panel.GetComponent<Image> ().color = new Color(0,0,0,alpha);
if (alphaTog <= 0) {
alpha += fadeSpeed * Time.deltaTime;
if (alpha >= 1f) { //if alpha is 1 or more
alphaTog = 1;
alpha = 1f; //set alpha to 1
}
} else if(alphaTog == 1){
alpha -= fadeSpeed * Time.deltaTime;
if (alpha <= 0) { //if alpha is 0 or less
aplha = 0f; //set alpha to 0
alphaTog = 2; //This stop it.
}
}