Greetings from Sydney, Australia

Here is my code :slight_smile:

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

public class NumberWizard : MonoBehaviour {

    int maxNum = 1000;
    int minNum = 1;
    int guessNum = 500;

    // Use this for initialization
    void Start ()
    {
        Debug.Log("I'm a wizard and I can guess any number that you are thinking!");
        Debug.Log("Pick a number in your head. Do not tell me. I will guess it anyway.");
        Debug.Log("The highest number you can pick is: " + maxNum);
        Debug.Log("The lowest number you can pick is: " + minNum);
        Debug.Log("Is your number " + guessNum + "? If it is, press ENTER");
        Debug.Log("If not, press UP if your number is higher. Press DOWN if it is lower");
        maxNum = maxNum + 1;
    }
	
	// Update is called once per frame
	void Update () {
        //Detect when the Up key is pressed down
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            Debug.Log("Up Arrow key was pressed.");
            minNum = guessNum;
            guessNum = (maxNum + minNum) / 2;
            Debug.Log("I guess your number is: " + guessNum + ". Press ENTER if this is your number");           
        }
        //Detect when the Down key is pressed down
        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            Debug.Log("Down Arrow key was pressed.");
            maxNum = guessNum;
            guessNum = (maxNum + minNum) / 2;
            Debug.Log("I guess your number is: " + guessNum + ". Press ENTER if this is your number");
        }
        //Detect when the Return key is pressed down
        else if (Input.GetKeyDown(KeyCode.Return))
        {
            Debug.Log("I always knew your number was " + guessNum + ". Next time pick a harder number to guess");
        }
    }
}

1 Like

Welcome to the community Cain! :slight_smile:

Thanks Rob! It’s really great to be part of it

1 Like

Privacy & Terms