2015/07/07//////////
by xbw/////////////////
Environment Unity 4.6.1////
Today, we realized the production of the game Welcome screen, First,
Presumably everyone has played the game, after a welcome interface will enter the game, which is what we want to achieve today;
、、、、、
This I put him a new scene, can not create a new scene, the code directly attached to the main camera, the following directly on the code it;
The Java language used;
Welcome code
var renderoverlay:displaytexturefullscreen;function Start () { Renderoverlay = getcomponent ( Displaytexturefullscreen); Renderoverlay.setstartcolor (color.white); Renderoverlay.setdelay (2.0);} function Update () { if (Renderoverlay.guicolor.a > 0) { renderoverlay.alphadown (time.deltatime); }}
Displaytexturefullscreen Code
var graphic = Texturegui (); (28,23); var guicolor:color;function ongui () { gui.color = Guicolor; if (graphic.texture) { GUI. Drawtexture (Rect (graphic.offset.x,graphic.offset.y,screen.width,screen.height), Graphic.texture, scalemode.stretchtofill,true);} } function AlphaUp (change:float) { guicolor.a + = Change;} function Setstartcolor (color:color) { guicolor = color; } function Setdelay (delay:float) { if (Guicolor.a >. 5) { GUICOLOR.A + = delay; } else { GUICOLOR.A-= delay; } } function Alphadown (change:float) { GUICOLOR.A-= change; }
These two codes require a class library,
class;
Import system.collections.generic;//Texturegui class:create a basic Class for creating and placing GUI elements//Textur E = The texture to display//offset = pixel offset from top left corner, can is modified for easy positioningclass texture GUI {var texture:texture;//useful:texture.width, texture.height var Offset:vector2;//. x and. y private var o Riginaloffset:vector2; Store the original to correctly reset anchor Pointenum point {topleft, topright, Bottomleft, BottomRight, Center}//wha T part of texture to position around? var anchorpoint = Point.topleft; Unity default is the from-top left corner of texture function setanchor () {//meant to was run ONCE at Start. Originaloffset = offset; if (texture) {//Check for NULL texture switch (anchorpoint) {//depending in where we want to center our OFFSE TS case Anchorpoint.topleft://Unity default; Case Anchorpoint.topright://Take the offset and go to the top right corner offset.x = originaloffset.x-texture.width; Break Case Anchorpoint.bottomleft://Bottom left corner of texture Offset.y = Originaloffset.y-texture.hei Ght Break Case Anchorpoint.bottomright://bottom right corner of texture Offset.x = Originaloffset.x-texture.wi Dth Offset.y = Originaloffset.y-texture.height; Break Case Anchorpoint.center://and The Center of the texture (useful for screen Center textures) Offset.x = ORIGINALOFFSET.X-TEXTURE.WIDTH/2; Offset.y = ORIGINALOFFSET.Y-TEXTURE.HEIGHT/2; Break }}}}//timer Class:class Timergui extends Texturegui {//Extend functionality from Texturegui for a Depreciati ng timer graphic var texturelend:texture; Left side of Full texture (non stretching part) var Offsetlend:vector2; Left side of the full texture (non stretching part) Start position var texturecenter:texture; Center of timer ('ll be stretched across width) var offsetcenter:vector2; var texturerend:texture; var Offsetrend:vector2; var timerperct:float = 1; Percentage (0 to 1) This stretches the center var desiredwidth:float = 403; Max width of the timer in pixels function settime (newtime:float) {timerperct = NewTime;//sets the percent Based on Value}}//Switchgui class:extends the Texturegui to being able to load in multiple textures and switch Between Themclass Switchgui extends Texturegui {var switchabletextures = new list.<texture> (); var currenttexture:int = 0; function Start () {if (Switchabletextures.count > 0) {texture = Switchabletextures[currenttexture]; }} function Changetexture (switchto:int) {if (SwitchTo < SwitchABletextures.count && switchTo >= 0) {texture = Switchabletextures[switchto]; Currenttexture = SwitchTo; } else {//debug.log (this + ": Tried to call invalid part of Switchtextures array!"); }} function up () {if ((currenttexture+1) < Switchabletextures.count) {++currentt Exture; Texture = Switchabletextures[currenttexture]; } else {//debug.log (this + ": at the top!"); }} function Nexttexture () {if (currenttexture+1) < Switchabletextures.count) {//If we are At the end of the array ++currenttexture; Texture = Switchabletextures[currenttexture]; } else {//loop to the beginning currenttexture = 0; Texture = Switchabletextures[currenttexture]; }} function down () {if ((currentTexture-1) >= 0) { --currenttexture; Texture = Switchabletextures[currenttexture]; } else {//debug.log (this + ": at the bottom!"); }}}//Location Class:class location {enum-point {topleft, topright, Bottomleft, BottomRight, Center} var pointlocation = Point.topleft; var Offset:vector2; function updateLocation () {switch (pointlocation) {Case PointLocation.TopLeft:offset = Vector2 (0,0); Break Case pointLocation.TopRight:offset = Vector2 (screen.width,0); Break Case pointLocation.BottomLeft:offset = Vector2 (0,screen.height); Break Case pointLocation.BottomRight:offset = Vector2 (screen.width,screen.height); Break Case pointLocation.Center:offset = Vector2 (SCREEN.WIDTH/2,SCREEN.HEIGHT/2); Break }}}class textureanchor {enum Point {topleft, topright, Bottomleft, BottomRight, Center} var anchorpoint = point . TopLeft; var Offset:vector2; function Update () {switch (anchorpoint) {Case anchorPoint.TopLeft:offset = Vector2 (0,0) ; Break Case anchorPoint.TopRight:offset = Vector2 (screen.width,0); Break Case anchorPoint.BottomLeft:offset = Vector2 (0,screen.height); Break Case anchorPoint.BottomRight:offset = Vector2 (screen.width,screen.height); Break Case anchorPoint.Center:offset = Vector2 (SCREEN.WIDTH/2,SCREEN.HEIGHT/2); Break } }}
The class does not need to be mounted, and the two outer two codes are mounted to the main camera,
A map in the red circle that needs to be set, that is, the welcome picture;;;,
Try the effect.;;
This is in the same scene, I saw two scenes, which requires a scene conversion,
The next section introduces, welcome students to learn from each other,
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Unity 3D Game opening screen fade implementation