unity官方demo学习之Stealth(四)屏幕渐变效果

本文介绍如何在Unity中实现屏幕渐变效果,包括添加DoneSceneFadeInOut脚本,设置淡入淡出速度和屏幕渐变标志。通过Awake()、Update()、FadeToClear()和FadeToBlack()等函数实现场景切换时的平滑过渡,优化资源使用,提高游戏体验。
摘要由CSDN通过智能技术生成
1,创建个对象命名为screenFader,x:0.5,y:0.5,添加组件Rendering->GUI Texture,将Texture文件夹中的swatch_black_dff拖入Texture属性栏中,将Pixel Inset都设为0

2,为screenFader添加脚本DoneSceneFadeInOut

using UnityEngine;
using System.Collections;


public class DoneSceneFadeInOut : MonoBehaviour
{
public float fadeSpeed = 1.5f;// Speed that the screen fades to and from black.


private bool sceneStarting = true;// Whether or not the scene is still fading in.


void Awake ()
{
// Set the texture so that it is the size of the screen and covers it.
guiTexture.pixelInset = new Rect(0f, 0f, Screen.width, Screen.height);
}


void Update ()
{
// If the scene is starting...
if(sceneStarting)
// ... call the StartScene function.
StartScene();
}


void FadeToClear ()
{
// Lerp the colour of the texture between itself and transparent.
guiTexture.color = Color.Lerp(guiTexture.color, Color.clear, fade
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值