国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > php开源 > 综合技术 > 添加启动游戏过渡场景Default Splash Scene(Unity3D开发之十三)

添加启动游戏过渡场景Default Splash Scene(Unity3D开发之十三)

来源:程序员人生   发布时间:2015-04-09 08:48:56 阅读次数:3854次

添加启动游戏过渡场景Default Splash Scene(Unity3D开发之103)

猴子原创,欢迎转载。转载请注明: 转载自Cocos2Der-CSDN,谢谢!

原文地址: http://blog.csdn.net/cocos2der/article/details/44099095

Unity5个人版会添加Unity Logo作为启动画面,我们既然没花钱,打个广告也应当。但Unity Logo结束后可以再添加1个自己的启动画面。

下面是添加1个简单的FadeIn->FadeOut过渡场景。

先看下效果图:
Unity启动过渡场景

代码以下 LHSplashScreens.cs:

using UnityEngine; using System.Collections; public enum FadeStatus { FadeIn, FadeWaiting, FadeOut } public class LHSplashScreens : MonoBehaviour { public string levelToLoad; public bool waitForInput; public float timeFadingInFinished; public Sprite splashSprite; private float m_fadeSpeed; private float m_waitTime; private float m_alpha; private FadeStatus m_status; private SpriteRenderer m_splashSpriteRenderer; public LHSplashScreens() { levelToLoad = ""; m_fadeSpeed = 0.3f; m_waitTime = 0.5f; m_status = FadeStatus.FadeIn; } void Awake() { Application.targetFrameRate = 60; } // Use this for initialization void Start () { if (Application.levelCount <= 1 || levelToLoad == "") { Debug.LogWarning("Invalid levelToLoad value."); } GameObject m_splashSpriteGO = new GameObject("SplashSprite"); m_splashSpriteGO.AddComponent<SpriteRenderer>(); m_splashSpriteRenderer = m_splashSpriteGO.GetComponent<SpriteRenderer>(); m_splashSpriteRenderer.sprite = splashSprite; Transform m_splashSpriteTransform = m_splashSpriteGO.gameObject.transform; m_splashSpriteTransform.position = new Vector2(0f, 0f); m_splashSpriteTransform.parent = this.transform; } // Update is called once per frame void Update () { FadeStatus fadeStatus = m_status; if (fadeStatus == FadeStatus.FadeIn) { m_alpha += m_fadeSpeed * Time.deltaTime; } else if (fadeStatus == FadeStatus.FadeWaiting) { if ((!waitForInput && Time.time >= timeFadingInFinished + m_waitTime) || (waitForInput && Input.anyKey)) { m_status = FadeStatus.FadeOut; } } else if (fadeStatus == FadeStatus.FadeOut) { m_alpha -= m_fadeSpeed * Time.deltaTime; } UpdateSplashAlpha(); } private void UpdateSplashAlpha() { if (m_splashSpriteRenderer != null) { Color spriteColor = m_splashSpriteRenderer.material.color; spriteColor.a = m_alpha; m_splashSpriteRenderer.material.color = spriteColor; if (m_alpha > 1f) { m_status = FadeStatus.FadeWaiting; timeFadingInFinished = Time.time; m_alpha = 1f; } if (m_alpha < 0) { if (Application.levelCount >= 1 && levelToLoad != "") { Application.LoadLevel(levelToLoad); } } } } }

在你工程中,建立1个新的场景,作为游戏的启动场景。

添加1个Empty GameObject, 添加上面的LHSplashScreens.cs脚本:
- Level To Load: 完成启动画面后你需要加载的场景
- Splash Sprite:过渡使用的logo sprite

最后完成后以下:

pro set


用了markdown以后,停不下来啊。呵呵

生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生