Hi There,
I have just started the course and am currently on the “Scope & Context of Variables” section in NumberWizard. Below is my script so far…
When I press Play in Unity the int guess = 500; works fine in my Start…however in my Update it shows the word ‘guess’ not ‘500’.
Any idea why this is happening? Sorry if this is a dumb question I’m new to all of this Thanks
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");
Debug.Log("I want you to pick a number, dont tell me what it is...");
Debug.Log("The highest number you can choose is: " + max);
Debug.Log("The lowest number you can choose is: " + min);
Debug.Log("Tell me if you number is higher or lower than: " + guess);
Debug.Log("Push Up = Higher, Push Down = Lower or Push Enter = Correct ");
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Debug.Log("Up Arrow key was pressed.");
min = guess;
Debug.Log("guess");
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
Debug.Log("Down Arrow key was pressed.");
}
else if (Input.GetKeyDown(KeyCode.Return))
{
Debug.Log("Return key was pressed.");
}
}
}