This is my project up to now:
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("Welcome to Number Wizard show! I am your number wizard Simon, and today we gonna play a guessing number game!");
Debug.Log("First, you need to pick a number in your mind!");
Debug.Log("The Highest number you can pick is: " + max);
Debug.Log("The Lowest number you can pick is: " + min);
Debug.Log("Tell me if your number is higher or lower 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))
{
if (guess < 1000)
{
Debug.Log("Banana! Your number sure is higher than " + guess + "!");
min = guess;
guess = (max + min) / 2;
Debug.Log("Your number must be " + guess + "!");
} else if (guess >= 1000)
{
Debug.Log("Sorry, but your number can't be higher than " + guess + "!");
}
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
if (guess > 1)
{
Debug.Log("Shibari! Your number is lower than " + guess + "!");
max = guess;
guess = (max + min) / 2;
Debug.Log("Your number must be " + guess + "!");
} else if (guess <= 1)
{
Debug.Log("Sorry, but your number can't be lower than " + guess + "!");
}
}
else
{
if (Input.GetKeyDown(KeyCode.Return))
{
Debug.Log("Yupiee! Your number is actually " + guess + "!");
}
}
}
}
I found one more problem that probably could be fix in next video or not, don’t know yet!
When I go to 1000 and click many times arrow for down this is what happened:
It counted as clicked, but doesnt go back to 1. It’s the same for 1 to 1000:
I try everything I can think about, but do nothing. If someone can help, it would be cool!
Also as you can see in my code, I add something new with “else if” event that stop the sign of “is lower than” or “is higher than” once its pass certain numbers, in this case 1000 and 1.