My Intro to Nuber Wizard (Welcome to number wizard, bro!)

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

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

// Start is called before the first frame update
void Start(){

    Debug.Log("Welcome to Number Wizard, bro!");
    Debug.Log("In this game you think of a number and I'll guess it.");
    Debug.Log("The highest number you can choose is: " + max);
    Debug.Log("The lowest number you can choose is: " + min);
    Debug.Log("Tell me if your number is higher or lower than my guess.");
    Debug.Log("My first guess is " + guess);
    Debug.Log("Up arrow is higher. Down arrow is lower. Enter/Return is correct.");
    max = max + 1;
}

// Update is called once per frame
void Update()
{
    if (Input.GetKeyDown(KeyCode.UpArrow))
    {
        Debug.Log("Too low? Hm...");
        min = guess;
        guess = (max + min) / 2;
        Debug.Log("How about " + guess);
    }
    else if (Input.GetKeyDown(KeyCode.DownArrow))
    {
        Debug.Log("Too high? Hm...");
        max = guess;
        guess = (max + min) / 2;
        Debug.Log("How about " + guess);
    }
    else if (Input.GetKeyDown(KeyCode.Return))
    {
        Debug.Log("Right on!");
    }
}

}

1 Like

Awesome code!

Privacy & Terms