Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to keep a random number fixed throughout the game?

In my project I've a temperature script that generates a random temperature.

Then there's a button called Temperature which calls that script on click. But everytime I click that button in the game, temperature is changed. I want that temperature to be fixed to the first random value it generates. Please guide how I can achieve this.

Below is the ScreenShot of my temperature script and them temperature button that shows temperature on being clicked.


Answers

  • Sl0thSl0th Member
    edited September 18

    Hey

    I am unsure about why you want to have a button for it, if it's supposed to give the same value each time. Could you set the number in awake and then also just update the UI there and then remove the button, RandomNumber and Update?

    If it's because you only want it to show after you've clicked the button, you could just generate the number in awake and then update the UI when clicking.

    Also, please use snipping tool or Windows key + shift + s or something similar when taking screenshots.

  • UnityUnity Member
    edited October 11

    Try calling your RandomNumber function through your start function

Sign In or Register to comment.