Hello,
I just started learning Unity/C# but I’m having a problem with one of my first scripts. When I try to run this script it Unity freeze and I have to close it using the Task Manager.
This is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class NumberWizard : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
int min = 1, max = 100;
Debug.Log("Hello and welcome to Number Wizard");
Debug.Log("Please choose a number between 1 and 100");
Debug.Log("Let me guess your number...");
GameWizard(min, max);
}
static void GameWizard(int min, int max)
{
Debug.Log("Your number is " + GuessNumber(min, max));
Debug.Log("Is it correct? Tell me if it is (C)orrect, too (B)ig or too (S)mall");
string userInput = Console.ReadLine().ToLower();
switch (userInput)
{
case "c":
Debug.Log("I was right! Nice :)");
return;
case "b":
Debug.Log("Retrying...");
GameWizard(min, GuessNumber(min, max));
return;
case "s":
Debug.Log("Retrying...");
GameWizard(GuessNumber(min, max), max);
return;
}
}
static int GuessNumber(int min, int max) => (min + max) / 2;
// Update is called once per frame
void Update()
{
}
}
I tried to use this code for a Console App and it works as expected, I can’t figure out what the problem is.
Thank you in advance.