打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Pico 淡入淡出

关于Unity 开发Pico 的淡入淡出功能  (适用于和我一样刚入门的新手)

废话少说  直接上流程

在Pvr_UnitySDK--Head--下面创建个空物体FadeInOutControl(名字可以随意取)
在FadeInOutControl下创建两个子物体 一个叫FadeIn 另一个叫FadeOut
将两个子物体上添加Sprite Renderer   并附一张图片
FadeIn 的Color 设置为(0,0,0,255)   FadeOut的Color 设置为(0,0,0,0)

在FadeIn物体添加“FadeIn”脚本  脚本如下

using System.Collections;using System.Collections.Generic;using UnityEngine;public class FadeIn : MonoBehaviour {    private void OnEnable()    {        this.GetComponent<SpriteRenderer>().color = new Color                (this.GetComponent<SpriteRenderer>().color.r,                this.GetComponent<SpriteRenderer>().color.g,                this.GetComponent<SpriteRenderer>().color.b,                1                );    }    void Update()    {        //如果透明度大于零,减少,在此前提下,最后一次执行如果小于零,等于零        if (this.GetComponent<SpriteRenderer>().color.a > 0)        {            this.GetComponent<SpriteRenderer>().color = new Color                (this.GetComponent<SpriteRenderer>().color.r,                this.GetComponent<SpriteRenderer>().color.g,                this.GetComponent<SpriteRenderer>().color.b,                this.GetComponent<SpriteRenderer>().color.a - 0.02f                );            if (this.GetComponent<SpriteRenderer>().color.a < 0)            {                this.GetComponent<SpriteRenderer>().color = new Color                (this.GetComponent<SpriteRenderer>().color.r,                this.GetComponent<SpriteRenderer>().color.g,                this.GetComponent<SpriteRenderer>().color.b,                0                );                //在最后一次执行后,关闭物体                this.gameObject.SetActive(false);            }        }    }}

在FadeOut物体添加“FadeOut”脚本 脚本如下

using System.Collections;using System.Collections.Generic;using UnityEngine;public class FadeOut : MonoBehaviour {    private void OnEnable()    {        this.GetComponent<SpriteRenderer>().color = new Color               (this.GetComponent<SpriteRenderer>().color.r,               this.GetComponent<SpriteRenderer>().color.g,               this.GetComponent<SpriteRenderer>().color.b,               0               );    }    void Update()    {        //如果透明度大于零,减少,在此前提下,最后一次执行如果小于零,等于零        if (this.GetComponent<SpriteRenderer>().color.a < 1)        {            this.GetComponent<SpriteRenderer>().color = new Color                (this.GetComponent<SpriteRenderer>().color.r,                this.GetComponent<SpriteRenderer>().color.g,                this.GetComponent<SpriteRenderer>().color.b,                this.GetComponent<SpriteRenderer>().color.a   0.02f                );            if (this.GetComponent<SpriteRenderer>().color.a > 1)            {                this.GetComponent<SpriteRenderer>().color = new Color                (this.GetComponent<SpriteRenderer>().color.r,                this.GetComponent<SpriteRenderer>().color.g,                this.GetComponent<SpriteRenderer>().color.b,                1                );                //在最后一次执行后,关闭物体                //this.gameObject.SetActive(false);            }        }    }}

在FadeInOutControl物体添加“Control_FadeInOut_Panel”脚本  并将两个子物体拖拽进去  脚本如下

using System.Collections;using System.Collections.Generic;using UnityEngine;public class Control_FadeInOut_Panel : MonoBehaviour {    public static Control_FadeInOut_Panel Instance;    public GameObject FadeInPanel;    public GameObject FadeOutPanel;    private void Awake()    {        Instance = this;    }	void Update () {			}    //开启执行一次淡入    public void OpenFade_In_Panel() {        FadeInPanel.SetActive(true);    }    //开启执行一次淡出    public void OpenFade_Out_Panel()    {        FadeOutPanel.SetActive(true);    }    //关闭淡入界面    public void CloseFade_In_Panel()    {        FadeInPanel.SetActive(false);    }    //关闭淡出界面    public void CloseFade_Out_Panel()    {        FadeOutPanel.SetActive(false);    }}

使用方法  调用Control_FadeInOut_Panel 里的方法就可以了  如:
Control_FadeInOut_Panel.Instance.CloseFade_Out_Panel();
Control_FadeInOut_Panel.Instance.OpenFade_In_Panel();

来源:https://www.icode9.com/content-4-377401.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
重回童年的经典系列☀️|【炸弹人小游戏】制作过程+解析 | 收藏起来跟曾经的小伙伴一起梦回童年!
Unity Ray 射线检测
slideUp(),slideDown(),slideToggle():,fadeIn(),fadeOut(),fadeTo()函数的使用
jQuery 事件
松软科技课堂:jQuery 效果 - 淡入淡出
【关于unity对象池的用法(话痨版)(c#)】
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服