Unity3d_ (game) Game Card 02_ Main Menu interface

Source: Internet
Author: User

Estimated 8.22 days before completion ~

splash screen, The main Menu interface , the check-off interface, the game interface,

Card 01_ Start Screen portal

Card 02_ Main Menu Interface Portal

Main Menu Interface

  

usingSystem.Collections;usingSystem.Collections.Generic;usingUnityengine;usingunityengine.scenemanagement;usingUnityengine.ui; Public enumtheme_id{Logo, Student} Public classScene_mainmenu:monobehaviour {//Use this for initialization    voidStart () {Gameobject.find ("logobtn"). Getcomponent<button> (). Onclick.addlistener (() ={onclickthemebtn (theme_id). Logo);        }); Gameobject.find ("studentbtn"). Getcomponent<button> (). Onclick.addlistener (() ={onclickthemebtn (theme_id). Student);        }); Gameobject.find ("closebtn"). Getcomponent<button> (). Onclick.addlistener (() ={Oncloseapp ();}); }        //Update is called once per frame    voidUpdate () {}voidonclickthemebtn (theme_id THEME) {Scenemanager.loadscene ("Selectlevel"); }    //Exit Program    voidOncloseapp () {application.quit (); } }
Scene_mainmenu.cs

Implementation process

Main Menu Interface

Add Canvas canvas Adaptive screen Resolution

Place two Game theme button and add Exit button,

Select Theme button buttons hang on two cartoons (Pokemon) pictures

Top Right Button exit program

Add Gameobject object, hang in Scene_mainmenu.cs script

usingSystem.Collections;usingSystem.Collections.Generic;usingUnityengine;usingunityengine.scenemanagement;usingUnityengine.ui; Public enumtheme_id{Logo, Student} Public classScene_mainmenu:monobehaviour {//Use this for initialization    voidStart () {Gameobject.find ("logobtn"). Getcomponent<button> (). Onclick.addlistener (() ={onclickthemebtn (theme_id). Logo);        }); Gameobject.find ("studentbtn"). Getcomponent<button> (). Onclick.addlistener (() ={onclickthemebtn (theme_id). Student);        }); Gameobject.find ("closebtn"). Getcomponent<button> (). Onclick.addlistener (() ={Oncloseapp ();}); }        //Update is called once per frame    voidUpdate () {}voidonclickthemebtn (theme_id THEME) {Scenemanager.loadscene ("Selectlevel"); }    //Exit Program    voidOncloseapp () {application.quit (); } }
Scene_mainmenu.cs

 Register three button click events

    void Start () {        gameobject.find ("logobtn"). Getcomponent<button> (). Onclick.addlistener (() ={onclickthemebtn (theme_id. Logo); });        Gameobject.find ("studentbtn"). Getcomponent<button> (). Onclick.addlistener (() = {onclickthemebtn (theme_id. Student); });        Gameobject.find ("closebtn"). Getcomponent<button> (). Onclick.addlistener (() = {Oncloseapp ();});    

  Enumerate game Theme Buttons

 Public enum theme_id{    Logo,    Student}

 Click the button to jump the game theme

Gameobject.find ("logobtn"). Getcomponent<button> (). Onclick.addlistener (() ={onclickthemebtn (theme_id. Logo); });       Gameobject.find ("studentbtn"). Getcomponent<button> (). Onclick.addlistener (() = {onclickthemebtn (theme_id. Student); });

    void onclickthemebtn (theme_id THEME)    {        Scenemanager.loadscene ("selectlevel");    }

  Click the Close button to exit the game program

    void Oncloseapp ()    {        application.quit ();    }

Data structure Analysis

Add new object, hang in level data script

usingSystem.Collections;usingSystem.Collections.Generic;usingUnityengine;//A related data structure[system.serializable] Public classlevelinfo{ Public intId//level ID     Public intRow;  Public intCol;  Public intCount//A random number of footage from a specified collection     Public stringDesc//Level Brief Description     Publicsprite[] sprites;} Public classLeveldata:monobehaviour { Publiclevelinfo[] levels;}
LevelData.cs

A related data structure

Declaring level serialization

[System.serializable]

[system.serializable] Public classlevelinfo{ Public intId//level ID     Public intRow;  Public intCol;  Public intCount//A random number of footage from a specified collection     Public stringDesc//Level Brief Description     Publicsprite[] sprites;} Public classLeveldata:monobehaviour { Publiclevelinfo[] levels;}

Id: Game Levels

Row: Level Line

Col: Level column

Count: The level appears random footage

Desc: Level notes Information

Size: Level

Set the level data as a prefab

1. The same type of      fast/convenient, create a large number of reusable resources can be used, this creation is done by a pre-set instantiation, the pre-set can use instantiate to complete the instantiation, to create multiple instances, in order to achieve the pre-defined name purposes, And all instantiated objects are linked to the original preset object, thus modifying the pre-instantiated object when all the created instantiation physical parameters are changed (updated) with the value modified by the preset object, which is also known as the inheritance of the object. It is also possible to make a separate modification to an instance object, so that it differs from other objects, which is called only for the overloading of the object can be dragged directly from the preset object to the scene, can be repeated in a scene with multiple presets of the same object, you can select the object in the object of the preset object. 2. Running instantiation    can perform instantiation operations while the program is running. Create a preset object and reference the preset object in the script. Relative script code is also relatively concise, need to modify and relatively simple as long as the preset object to modify it, do not need to add other changes to the code, compared with the normal script created by the default object, all are pre-set objects cloned, can improve the efficiency of program operation and save memory space
Unity: Precast body

Copy the Leveldatalogo preform, named Leveldatastudent, modify the picture style under sprites, this style is the second game theme

Do not forget "apply", apply to Leveldatastudent preform

Unity3d_ (game) Game Card 02_ Main Menu interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.