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