I’ve tried slightly changing the code for number wizard while including parameters in my NextGuess function. But for some reason, using this function causes the game to not work (stuck after the second guess). Keep in mind that the same code without the use of this function worked fine. What is the problem?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NumberWizard : MonoBehaviour
{
// Start is called before the first frame update
int max = 1000;
int min = 1;
int guess = 500;
void Start()
{
StartGame();
}
void StartGame()
{
Debug.Log("Welcome to Number Wizard! Thanks for playing!");
Debug.Log("Pick a number: ");
Debug.Log("Highest number you can pick is: " + max);
Debug.Log("Lowest number you can pick is: " + min);
Debug.Log("Tell me if your number is higher or lower than " + guess);
Debug.Log("Press up arrow = Higher, press down arrow = Lower, press Enter = Correct.");
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
min = guess + 1;
if ((min + max) / 2 == guess)
{
Debug.Log("Your number has to be " + guess);
}
else
{
NextGuess("higher", "lower", guess, min, max);
}
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
max = guess - 1;
if ((min + max + 1) / 2 == guess)
{
Debug.Log("Your number has to be " + guess);
}
else
{
NextGuess("lower", "higher", guess, min, max);
}
}
else if (Input.GetKeyDown(KeyCode.Return))
{
Debug.Log("I found your number. It is " + guess);
}
}
void NextGuess(string string1, string string2, int guess, int min, int max)
{
Debug.Log("You told me that the number was " + string1 + " than " + guess + ". It should still be " + string2 + " than " + min);
guess = (min + max) / 2;
Debug.Log("New guess is " + guess);
}