5unity-3d Day05 Play Hamster Games

Source: Internet
Author: User
Tags gopher

Wrote a mouse game with a GUI Hiahia

The camera's script Riga code:

usingUnityengine;usingSystem.Collections; Public classMolescript:monobehaviour { PublicGuiskin Skin;  Publictexture2d bgimg;  Public intnum;  Publictexture2d[] Susliks =Newtexture2d[ A];  PublicRect[] pos =Newrect[9];  Public intID;  Public floatTime ;  Public BOOLFlag; //Use this for initialization    voidStart () {pos[0] =NewRect (150f, 170f, 100f, 100f); pos[1] =NewRect (300f, 170f, 100f, 100f); pos[2] =NewRect (450f, 170f, 100f, 100f); pos[3] =NewRect (150f, 270f, 100f, 100f); pos[4] =NewRect (300f, 270f, 100f, 100f); pos[5] =NewRect (450f, 270f, 100f, 100f); pos[6] =NewRect (150f, 370f, 100f, 100f); pos[7] =NewRect (300f, 370f, 100f, 100f); pos[8] =NewRect (450f, 370f, 100f, 100f); time=0; Flag=false; }        //Update is called once per frame    voidUpdate () {}voidOngui () {Gui.skin=Skin; Gui. Label (NewRect (0,0, Screen.width, screen.height), bgimg);  for(inti =0; I < Pos. Length; i++) {GUI. Label (Pos[i], susliks[0]);    } Game (); }    //Control Game Flow    voidGame () { time+=Time.deltatime; if(Time >2.5f)        {            //Random One positionid = random.range (0,9); time=0; Num=0; Flag=false; }        //judge it or go back.        if(flag) {Susliksdown (Pos[id]); }        Else{susliksup (Pos[id]); }         }    //out of the ground rat    voidSusliksup (Rect position) {if(Num < One) {num+=1; }        Else{num= One; }        if(GUI. Button (position, Susliks[num])) {flag=true; time=2.2f; }    }    //Gopher down!    voidSusliksdown (Rect position) {print (num); if(Num >0) {num-=2; }        Else{num=0; } GUI.    Button (position, susliks[num]); }}

: Gopher or whatever is looking for the picture

5unity-3d Day05 Play Hamster Games

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.