Hi, I’ve been having an issue with trying to make the nested if-statements in my update method work as intended . Totally new to C# but have a little experience with Python. I’ve tried all sorts of work arounds to no success and would appreciate something helping me with this little exercise.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NumberWizard : MonoBehaviour
{
int minValue;
int maxValue;
int guess;
string replay;
void Start()
{
StartGame();
}
void StartGame()
{
minValue = 1;
maxValue = 1000;
guess = (1000 + 1) / 2;
Debug.Log("Welcome to number wizard, let's have some fun !");
Debug.Log($"Please pick a number between {minValue} and {maxValue}");
Debug.Log($"Tell me if your number is higher or lower than my {guess}");
Debug.Log("Push Up = Higher | Push Down = Lower | Push Enter = Correct");
maxValue = maxValue + 1;
}
void NextGuess()
{
guess = (maxValue + minValue) / 2;
Debug.Log($"Is your guess higher or lower than {guess} ?");
}
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
minValue = guess;
NextGuess();
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
maxValue = guess;
NextGuess();
}
else if (Input.GetKeyDown(KeyCode.Return))
{
Debug.Log("Sweet, I'm a genius ! Want to play again ? (Y | N)");
if (Input.GetKeyDown(KeyCode.Y))
{
StartGame();
}
else if (Input.GetKeyDown(KeyCode.N))
{
Debug.Log("Thanks for playing!");
}
//Debug.Log("Play again ? (Y | N)");
//replay= System.Console.ReadLine();
//if (replay == ("Y"))
//{
// StartGame();
//}
//else if (replay == ("N"))
//{
// Debug.Log("Thanks for playing mate");
//}
}
}
}