Add Launch Game transition scenario default Splash scene (Unity3d development 13)
Monkey original, welcome reprint. Reproduced please specify: Reproduced from COCOS2DER-CSDN, thank you!
Original address: http://blog.csdn.net/cocos2der/article/details/44099095
Unity5 Personal Edition will add Unity logo as a splash screen, since we have no money, we should make an advertisement. But once the Unity logo is finished, you can add your own splash screen.
The following is a simple fadein->fadeout transition scenario to add.
First look at the following:
The code is as follows LHSplashScreens.cs:
usingUnityengine;usingSystem.Collections; Public enumfadestatus{FadeIn, fadewaiting, FadeOut} Public classLhsplashscreens:monobehaviour { Public stringLeveltoload; Public BOOLWaitforinput; Public floattimefadinginfinished; PublicSprite Splashsprite;Private floatM_fadespeed;Private floatM_waittime;Private floatM_alpha;PrivateFadestatus M_status;PrivateSpriterenderer M_splashspriterenderer; Public Lhsplashscreens() {leveltoload =""; M_fadespeed =0.3F M_waittime =0.5F M_status = Fadestatus.fadein; }voidAwake () {application.targetframerate = -; }// Use this for initialization voidStart () {if(Application.levelcount <=1|| Leveltoload = ="") {debug.logwarning ("Invalid leveltoload value."); } Gameobject M_splashspritego =NewGameobject ("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 =NewVector2 (0F0f); M_splashspritetransform.parent = This. Transform; }//Update is called once per frame voidUpdate () {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); } } } }}
In your project, create a new scene as a starting scene for the game.
Add an empty gameobject and add the LHSplashScreens.cs script above:
-Level to load: The scene you need to load after completing the splash screen
- Splash Sprite: The logo sprite used for the transition
After the final completion are as follows:
After using the markdown, I can't stop. Oh
Add Launch Game transition scenario default Splash scene (Unity3d development 13)