Unity_Dotween_隐藏物体和UI界面

1.隐藏物体(方式一二)

参数一 0-1的值 1为显示 0为透明

参数二 

Unity_Dotween_隐藏物体和UI界面_第1张图片

Unity_Dotween_隐藏物体和UI界面_第2张图片

参数三 完成动画的时间  

material.DOFade(1, "_Color", 2);



    Material material;


    // Start is called before the first frame update
    void Start()
    {
        //获取物体材质
        material = GetComponent().material;
    }

    // Update is called once per frame
    void Update()
    {    
        //改变物体Alpha值 显示物体 
        material.DOFade(1, "_Color", 2);
        //改变物体Alpha值 隐藏物体
        //material.DOColor(Color.clear, "_Color", 2);
    }

⚠️注意  如果物体变黑 没有变成透明 需要把材质球修改成?

Unity_Dotween_隐藏物体和UI界面_第3张图片

 

2.隐藏UI界面

隐藏UI界面 需要给 Canvas面板 添加 Canvas Group组件

Unity_Dotween_隐藏物体和UI界面_第4张图片

关键代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public class HideCanvas : MonoBehaviour
{
    
    CanvasGroup canvasGroup;
    // Start is called before the first frame update
    void Start()
    {
        //获取Canvas 身上的 CanvasGroup组件
        canvasGroup = GetComponent();
    }

    // Update is called once per frame
    void Update()
    {
        //隐藏UI界面
        canvasGroup.DOFade(0,2);
    }
}

 

你可能感兴趣的:(DoTween,触摸屏)