More souls for the Number Wizard

Good evening! First post here, as I’ve just completed the Number Wizard video and wanted to join in and show the code I’m working with at this point.

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

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

    // Start is called before the first frame update
    void Start()
    {
        
        Debug.Log("What have we here? Another misguided challenger has come to be humbled by the Number Wizard!");
        Debug.Log("Very well, choose a number between " + min + " and " + max +".");
        Debug.Log("If your number is higher than the guess, press the up key.");
        Debug.Log("If your number is lower than the guess, press the down key.");
        Debug.Log("If I've guessed the number correctly, press the enter key.");
        Debug.Log("Is your number higher or lower than " + guess + "?");
        max = max + 1;
        guessCount = 1;

    }

    // Update is called once per frame
    void Update()
    {
        //Detect when the up arrow key is pressed down
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            min = guess;
            guess = (max + min) / 2;
            Debug.Log("Is your number lower than " + guess + "?");
            guessCount += 1;
        }

        //Detect when the down arrow key is pressed down
        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            max = guess;
            guess = (max + min) / 2;
            Debug.Log("Is your number higher than " + guess + "?");
            guessCount += 1;
        }

        //Detect when the enter key is pressed down
        else if (Input.GetKeyDown(KeyCode.Return))
        {
            Debug.Log("I win!");
            Debug.Log("Having guessed your predictable choice in just " + guessCount + " guesses, I remain the champion!");
            Debug.Log("Who's next?");
        }
    }
}
1 Like

Thank you for sharing! Looks incredible🤩