Unity 2D - Lesson 43: Course Correction: Unity 2d Lecture 43

Hey team,
Wanted to post a correction for this lesson.
In the lesson Rick removes the max = max + 1 logic from the StartGame() code to correct the max guess being 1001. He then mentions a correction later in the video, but instead changes the code into the NextGuess() function where he changes the code from
guess = Random.Range(min, max) to guess = Random.Range(min, max+1).

However, this is still wrong as it breaks the previous rule of a number being allowed to be guessed more than once. As example, if the random generated guess was 250, and I said it was lower it will then set the max to 250 + 1 which allows 250 to be guessed again.

The code was correct up until Rick removed the max = max + 1 from start game and added guess = Random.Range(min, max+1)
By setting the original max to max + 1 this allows 1000 to be picked (important as Random.Range max is exclusive) and any number assigned to max later will then be excluded, which is good because it was already guessed.

If I am wrong or misinterpreting something please let me know

I think you mean inclusive, as the min and max for Random.Range() includes the min and max values within that range. So in saying that all you’d need to do is set the values between 1, 999 with the current max+1 resolution.

Privacy & Terms