Howdy, I’ve just started following the course but I’ve hit two problems.
-
My keyboard input is still reading the up, down, enter keys all at one if pressed all at once.
-
My ‘Guess’ numbers are not scaling higher or lower, the up and down arrow keys just result in ‘guess’ to pop up.
Here is my code so far. Any advice would be loved.
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()
{
Debug.Log("Welcome to number wizard, yo");
Debug.Log("Choose a number Mortal");
Debug.Log("The highest you may pick is: " + max);
Debug.Log("The lowest is: " + min);
Debug.Log("Tell me if your number is higher or lower than 500");
Debug.Log("Push Up = Higher, Push Down = Lower, Enter = Correct");
max = max + 1;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Debug.Log("Up Arrow key was pressed.");
min = guess;
guess = (max + min) / 2;
Debug.Log("guess");
}
//Detect when the down arrow key is pressed down
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
Debug.Log("Down Arrow key was pressed.");
max = guess;
guess = (max + min) / 2;
Debug.Log("guess");
; }
//Detect when the Return key is pressed down
else if (Input.GetKeyDown(KeyCode.Return))
{
Debug.Log(“Return key was pressed.”);
}
}
}