NWUI: Mr. Meeseeks edition

Hey guys, just wanted to share my Rick and Morty inspired Number Wizard UI with you all. I spent way too long on it!

https://sharemygame.com/@markymark9/nwui-mr-meeseeks

I noticed there’s a bug where clicking higher repeatedly will let you get to over 1000 (which is the current max defined in the inspector). It doesn’t really matter as I won’t be revisiting it, but thought it would be good practice to try and work out exactly why it’s happened. As far as I can tell, my code is identical to Rick’s.

using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class NumberWizard : MonoBehaviour
{
    [SerializeField] int max;
    [SerializeField] int min;
    [SerializeField] TextMeshProUGUI guessText;

    int guess;

    void Start()
    {
        StartGame();
    }

    void StartGame()
    {
        NextGuess();
    }

    public void OnPressHigher()
    {        
        min = guess + 1;
        NextGuess();
    }

    public void OnPressLower()
    {
        max = guess - 1;
        NextGuess();
    }

    void NextGuess()
    {
        guess = Random.Range(min, max + 1);
        guessText.text = guess.ToString();
    }
}
1 Like

I noticed the same thing. I think its tied to change in the unity docs. Remove the +1 from your parameters for the Random.Range and test it out. That’s what worked for me.

Didn’t work for me. It still goes up to 1001 or 1002.

Found a solution for it going above 1000.

void NextGuess()
{
guess = Random.Range(_min,_max);
if(guess > 1000)
{
guess = 1000;
}

    guessText.text = guess.ToString();
}

Privacy & Terms