Hey bud, welcome to numberr wizerd my guy

Here is my code! I also added a feature to restart the game by pressing enter after your number is guessed.

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

public class NumberWizard : MonoBehaviour
{
    int guess;
    int min;
    int max;
    bool gamelive = true;
    
    void UpdateGuess()
    {
        guess = (max + min) / 2;
    }

    void NumberWizardInstance() {
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            Debug.Log("You say it is higher...");
            min = guess;
            UpdateGuess();
            Debug.Log("Is it " + guess + "?");
        }
        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            Debug.Log("Lower eh?");
            max = guess;
            UpdateGuess();
            Debug.Log("Is it " + guess + "?");
        }
        else if (Input.GetKeyDown(KeyCode.Return))
        {
            Debug.Log("Hooray! Your number is: " + guess);
            Debug.Log("Press enter to play again...");
            gamelive = false;
        }
    }

    // Start is called before the first frame update
    void Start()
    {
        guess = 500;
        min = 1;
        max = 1000;
        Debug.Log("Hey bud, welcome to numberr wizerd my guy.");
        Debug.Log("I want you to think of a number...");
        Debug.Log("No higher than "  + max);
        Debug.Log("No lower than " + min);
        Debug.Log("Tell me if your number is higher or lower than " + guess + ".");
        Debug.Log("Up Arrow = Higher, Down Arrow = Lower, Enter = Correct");
        //allow guess to get to 1000
        max = max + 1;

    }

    // Update is called once per frame
    void Update()
    {
        
        if(gamelive)
        {
            NumberWizardInstance();
        }   else
        {
            if (Input.GetKeyDown(KeyCode.Return))
            {
                Start();
            }

        }     

    }
}

Oops looks like i skipped to what the next lecture is about

Privacy & Terms