Unity 收藏本版 已有9人收藏 +发表新主题
查看: 28569|回复: 0
打印 上一主题 下一主题

[分享] [脚本]Unity 切换游戏场景时屏幕淡入淡出效果

[复制链接]

[分享] [脚本]Unity 切换游戏场景时屏幕淡入淡出效果

朋克耀仔 发表于 2013-8-12 02:00:21 浏览:  28569 回复:  0 只看该作者 复制链接
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using UnityEngine;
using System.Collections;
  
public class SceneFadeInOut : MonoBehaviour
{
    public float fadeSpeed = 1.5f;
      
    private bool sceneStarting = true;
    private bool sceneEnding = false;
      
    void Awake()
    {
        guiTexture.pixelInset = new Rect(0f, 0f, Screen.width, Screen.height);
    }
      
    void Update()
    {
        if (sceneStarting)
        {
            StartScene();
        }
         
        if (sceneEnding)
        {
            EndScene();
        }
    }
      
    void FadeToClear()
    {
        guiTexture.color = Color.Lerp(guiTexture.color, Color.clear, fadeSpeed * Time.deltaTime);
    }
      
    void FadeToBlack()
    {
        guiTexture.color = Color.Lerp (guiTexture.color, Color.black, fadeSpeed * Time.deltaTime);
    }
      
    void StartScene()
    {
        FadeToClear();
         
        if(guiTexture.color.a < 0.05f)
        {
            guiTexture.color = Color.clear;
            guiTexture.enabled = false;
            sceneStarting  = false;
        }
    }
      
    public void EndScene()
    {
        guiTexture.enabled = true;
        FadeToBlack();
         
        if(guiTexture.color.a >= 0.95f)
        {
            sceneEnding = false;
            Application.LoadLevel(1);
        }
    }
      
    void OnGUI()
    {
        if (!sceneStarting && GUI.Button (new Rect(0,0,100,100),"NewLevel"))
        {
            sceneEnding = true;
        }
    }
  
}



分享至:
| 人收藏
回复

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Copyright © 2013-2017 ARinChina-增强现实中国技术论坛   All Rights Reserved.