Number Wizard code

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("Good to meet you sir/madame this game is number wizard, it is very good game no?");
        Debug.Log("Pick a number");
        Debug.Log("The highest number possible is: " + max);
        Debug.Log("The lowest number possible is: " + min);
        Debug.Log("Tell me if your number is higher or lower than" + guess); ;
        Debug.Log("Push down = Lower, Push up = Higher, Press ENTER if correct");
        max = max + 1;
    }

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

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

        //Detect when the Return key is pressed down
        else if (Input.GetKeyDown(KeyCode.Return))
        {
            Debug.Log("Return key was pressed.");
        }



    }
}

1 Like

Nice Number Wizard code :+1:

Privacy & Terms