I try to create a function that gives the player an option to start the game again by press a button?
But somehow, it does not work. What have I done wrong?
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()
{
GameStart();
}
void GameStart()
{
max = 1000;
min = 1;
guess = Random.Range(min, max);
Debug.Log(“Welcome to number wizard, boys!!!”);
Debug.Log(“Pick your number”);
Debug.Log("Highest number is " + max);
Debug.Log("Lowest number 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 += 1;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
min = guess;
NextGuess();
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
max = guess;
NextGuess();
}
else if (Input.GetKeyDown(KeyCode.Return))
{
Debug.Log(“Boy, you are breathtaking”);
Debug.Log(“Do you want to play again? Press Space to play again!”);
PlayAgain();
}
}
void NextGuess()
{
guess = (min + max) / 2;
Debug.Log("Is your number lower or higher than " + guess + “?”);
Debug.Log(“If correct, congratulation! If not, try again!”);
}
void PlayAgain()
{
if (Input.GetKeyDown(KeyCode.Space))
{
GameStart();
}
}
}