Hi all,
I’ve just been following the Number Wizard videos and it’s all pretty much perfect except it won’t restart properly at the end of the first round and the “Return” button seems to become inactive. Would someone by kind enough to check my code please?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NumberWizard : MonoBehaviour
{
int max;
int min;
int guess;
// Start is called before the first frame update
void Start()
{
StartGame();
}
void StartGame()
{
max = 1000;
min = 1;
guess = 500;
Debug.Log("Ahoyyyy, Welcome to number wizard me hearty!");
Debug.Log("Polly says that It's time to think of a number, but don't tell me or 'im");
Debug.Log("The lowest number you can pick is: " + min);
Debug.Log("The hghest number you can pick is: " + max);
Debug.Log("What are you waiting for, go forth Greybeard. Solve the mystery!");
Debug.Log("Ye-arghhh Hurry up!");
Debug.Log("Is yeee number higher or lower than 500");
Debug.Log("Press up = High-arghh, Press Down = Low-arghh, Press Enter = Correct!! Ahoy!! Get the Rum in!");
max = max + 1;
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
min = guess;
NextGuess();
Debug.Log(guess);
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
max = guess;
NextGuess();
}
else if (Input.GetKeyDown(KeyCode.Return))
{
Debug.Log("Yee-arghhhh! get in mate! Let's go again. Is your number high-arghh or low-arghh than 500?");
StartGame();
}
}
void NextGuess()
{
guess = (max + min) / 2;
Debug.Log("Is the number high-arghh or low-arghh than.." + guess);
}
}