using UnityEngine;
using UnityEngine.UI;
public class CrossFadeAlphaTest : MonoBehaviour
{
Graphic graphicText;
Graphic graphicImage;
public Text text01;//文字
public Image image1;//图片
void Start()
{
graphicText = text01.GetComponent<Graphic>();
graphicImage = image1.GetComponent<Graphic>();
graphicText.CrossFadeAlpha(0f, 0f, false);//开始时隐藏透明度为0
graphicImage.CrossFadeAlpha(0f, 0f, false);
}
//淡出
void Hidden()
{
graphicText.CrossFadeAlpha(0f, 2f, false);
graphicImage.CrossFadeAlpha(0f, 2f, false);
}
//一秒淡入,4秒后淡出
public void Show()
{
graphicText.CrossFadeAlpha(1f, 1f, true);//(1-0透明度,变化时间,显示或隐藏)
graphicImage.CrossFadeAlpha(1f, 1f, true);
Invoke("Hidden", 4);
}
}