Trouble with Section 2 Lecture 19 guess = (max + min) / 2; [solved]

Hello,
I ran into a roadblock trying to follow along with the coding from lecture 19. I can’t seem to get my controls back after setting the “int” variable to “guess” when I hit play in Unity. It only responds to KeyCode.Return and saying “I won”. Thanks for any help you can give me on what I’m doing wrong with this script. I’ve attached screenshots below.

Much appreciated,
Jon

using UnityEngine;
using System.Collections;

public class NumberWizard : MonoBehaviour {
// Use this for initialization
int max = 1000;
int min = 1;
int guess = 500;

void Start () {
	print ("Welcome to Number Wizard");
	print ("Pick a number in your head, but don't tell me!");
	
	print ("The highest number you can pick is " + max);
	print ("The lowest number you can pick is " + min);
	
	print ("Is the number higher or lower than " + guess);
	print ("Up = higher, down = lower, return = equal");
}

// Update is called once per frame
void Update () {
	if (Input.GetKeyDown(KeyCode.UpArrow)) {
		min = guess;
		guess = (max + min) / 2; 
	} else if (Input.GetKeyDown(KeyCode.DownArrow)) {
		max = guess;
		guess = (max + min) / 2; 	
	} else if (Input.GetKeyDown(KeyCode.Return)) {
		print("I won");
		
	}	
}

}

void Update () {
if (Input.GetKeyDown(KeyCode.UpArrow)) {
min = guess;
guess = (max + min) / 2;
} else if (Input.GetKeyDown(KeyCode.DownArrow)) {
max = guess;
guess = (max + min) / 2;
} else if (Input.GetKeyDown(KeyCode.Return)) {
print(“I won”);

}
}

Morning,

looking at this, the only part of this Update loop that shows anything to the console is the ‘else if’ that checks for the return key.

looking through the lecture, looks like you should be showing to the console when the up or down arrow is pressed.

if (Input.GetKeyDown(KeyCode.UpArrow)) {
	min = guess;
	guess = (max + min) / 2; 
            print ("Higher or lower than " + guess);    // TRY ADDING THIS LINE
} else if (Input.GetKeyDown(KeyCode.DownArrow)) {
	max = guess;
	guess = (max + min) / 2;
            print ("Higher or lower than " + guess);    // TRY ADDING THIS LINE

OboShape,

Thank you very much for your help! I’m back up and running (or at least stumbling)!

Cheers,
Jon

No worries Jon,

A journey is always one step at a time :wink:

glad to help out.