My Number Greeting

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NumberWizard : MonoBehaviour {
   
    int max = 1000;
    int min = 1;
    int guess = 500;

    // Use this for initialization
    void Start () {

        Debug.Log("Welcome to this awesome number wizard!");
        Debug.Log("Please pick a number from " + min + " to " + max + ".");
        Debug.Log("Tell me if your number is higher or lower than " + guess + ".");
        Debug.Log("Push Up = Higher, Push Down = lower, Push Enter = Correct");
        max = max + 1;
	}
	
	// Update is called once per frame
	void Update () {
       
        if (Input.GetKeyDown(KeyCode.UpArrow)) 
        {
            Debug.Log("So the number is above my guess, hmm...");
            min = guess;
            guess = (max + min) / 2;
            Debug.Log("My new guess is " + guess + ".");
        }

        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            Debug.Log("So the number is below my guess, hmm..");
            max = guess;
            guess = (max + min) / 2;
            Debug.Log("My new guess is " + guess + ".");
        }

        else if (Input.GetKeyDown(KeyCode.Return))
        {
            Debug.Log("The number wizard has guessed correctly!");
        }
    }
}
1 Like

Privacy & Terms