Added a GUI to Number Wizard

As part of an ongoing course I’m taking in Unity game development, I added a menu and splash screen to the number guessing game I made earlier. You can play the game by clicking the picture below:

nw-screenshotYou can find the full code below:

Number Wizard UI (C#)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
 
public class NumberWizard : MonoBehaviour {
 
	// Use this for initialization
	int max;
	int min;
	int guess;
	int counter;
 
	int maxGuessesAllowed;
 
	public Text text;
 
	void Start () {	
		StartGame ();	
	}
 
	void StartGame () {
		max = 1000;
		min = 1;
		guess = 500;
		counter = 1;
		max = max+1;
		maxGuessesAllowed = 9;
	}
 
	public void GuessHigher(){
		min = guess;
		NextGuess ();
	}
 
	public void GuessLower(){
		max = guess;
		NextGuess ();
	}
 
	void NextGuess(){
		guess = (max+min)/2;
		counter = counter+1;
		text.text = "Is your number " +guess +"?\n\n I have guessed " +counter +" times.";
		maxGuessesAllowed = maxGuessesAllowed-1;
		if (maxGuessesAllowed <= 0){
			Application.LoadLevel("Win");
		} 
	}
 
}

[collapse]

As always, any tips or comments are greatly appreciated.

Leave a Reply

Your email address will not be published. Required fields are marked *