欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Unity實(shí)現(xiàn)UI漸隱漸顯效果

 更新時(shí)間:2020年04月16日 08:58:55   作者:Diviner_占卜者  
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)UI漸隱漸顯效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Unity實(shí)現(xiàn)UI漸隱漸顯效果的具體代碼,供大家參考,具體內(nèi)容如下

1、在UI對(duì)象上添加組件:CanvasGroup;

2、在對(duì)象上添加腳本:UI_FadeInFadeOut 腳本;

腳本信息:

(Blocks Raycasts=true可以交互;Blocks Raycasts=false無(wú)法交互)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// UI的漸入漸出
/// </summary>
public class UI_FadeInFadeOut : MonoBehaviour {
 private float UI_Alpha = 1;    //初始化時(shí)讓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;
  }
 
  if (UI_Alpha != canvasGroup.alpha)
  {
   canvasGroup.alpha = Mathf.Lerp(canvasGroup.alpha, UI_Alpha, alphaSpeed * Time.deltaTime);
   if (Mathf.Abs(UI_Alpha - canvasGroup.alpha) <= 0.01f)
   {
    canvasGroup.alpha = UI_Alpha;
   }
  }
 }
 public void UI_FadeIn_Event()
 {
  UI_Alpha = 1;
  canvasGroup.blocksRaycasts = true;  //可以和該對(duì)象交互
 }
 public void UI_FadeOut_Event()
 {
  UI_Alpha = 0;
  canvasGroup.blocksRaycasts = false;  //不可以和該對(duì)象交互
 }
}

3、需要顯示時(shí),添加  UI_FadeIn_Event()  事件;

4、需要隱藏時(shí),添加  UI_FadeOut_Event()  事件;

5、注意:父物體隱藏和顯示時(shí),子物體同樣也隱藏和顯示。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論