Cannot access alpha channel to make stuff fade in and out…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Crossfade : MonoBehaviour {
public bool IsText;
public bool IsImage;
public float FadeTime;
public float FadoutTime;
// Use this for initialization
void Start () {
if (IsText == true) {
this.gameObject.GetComponent<Text> ().color = Color.a = 0;
}
if (IsImage == true) {
this.gameObject.GetComponent<Image> ().color = Color.a = 0;
}
}
// Update is called once per frame
void Update () {
FadeTime += 1 * Time.deltaTime;
if (IsText == true) {
this.gameObject.GetComponent<Text> ().color = Color.a += 0.1f * Time.deltaTime;
if(FadeTime == FadoutTime ){
this.gameObject.GetComponent<Text> ().color = Color.a -= 0.1f * Time.deltaTime;
}
}
if (IsImage == true) {
this.gameObject.GetComponent<Text> ().color = Color.a -= 0.1f * Time.deltaTime;
}
}
}