Unity实现实现UI渐隐渐显效果渐隐渐显效果
本文实例为大家分享了Unity实现UI渐隐渐显效果的具体代码,供大家参考,具体内容如下
1、在UI对象上添加组件:CanvasGroup;
2、在对象上添加脚本:UI_FadeInFadeOut 脚本;
脚本信息:
(Blocks Raycasts=true可以交互;Blocks Raycasts=false无法交互)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// UI的渐入渐出
/// </summary>
public class UI_FadeInFadeOut : MonoBehaviour {
private float UI_Alpha = 1; //初始化时让UI显示
public float alphaSpeed = 2f; //渐隐渐显的速度
private CanvasGroup canvasGroup;
// Use this for initialization
void Start () {
canvasGroup = this.GetComponent<CanvasGroup>();
}
// Update is called once per frame
void Update () {
if (canvasGroup == null)
{
return;
}
- 1
- 2
前往页