Balearic_Number_Wizard

Here is my sample of the code lesson!!

{ // For the fun ~

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

public class NumberWizard : MonoBehaviour
{
int max = 10000;
int min = 1;
int guess = 5000;

// Start is called before the first frame update
void Start()
{
    Debug.Log("Hey! you good? Nice, here we have a magic game for you.");
    Debug.Log("Pick a number and keep it in secret, we will try to find it.");
    Debug.Log("The number can't be superior to: " + max);
    Debug.Log("The number can't be inferior to: " + min);
    Debug.Log("So, pick a number between " + min + " and " + max + ".");
    Debug.Log("Now you have to tell me if your number is lower or higher than " + guess + ".");
    Debug.Log("Push Up = Higher, Push Down = Lower, Push Enter = Correct.");
    max = max + 1;
}

// Update is called once per frame
void Update()
{
    if (Input.GetKeyDown(KeyCode.UpArrow))
    {
        Debug.Log("My number is higher.");
        min = guess;
        guess = (max + min) / 2;
        Debug.Log("Our guess is: " + guess);
    }
    else if (Input.GetKeyDown(KeyCode.DownArrow))
    {
        Debug.Log("My number is lower.");
        max = guess;
        guess = (max + min) / 2;
        Debug.Log("Our gues is: " + guess);
    }
    else if (Input.GetKeyDown(KeyCode.Return))
    {
        Debug.Log("That's my number, thanks it was really fun!!");
    }
}

}

}

Privacy & Terms