- Home /
This question was
closed Oct 16, 2020 at 03:10 PM by
gjf.
how to Save A random generated number and use it
I want to use a random generated number and save it in a variable. i tried using X = public float x = Random.Range(minNb, maxNb)
but it doesn't work. Here is the rest of my script.
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
public class Score : MonoBehaviour
{
public float score = 0;
public float scoreMulti = 5;
public float minNb = 100;
public float maxNb = 200;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
score += Time.deltaTime * scoreMulti;
if (score == 70)
{
//save random generated number
}
}
}
Comment
You were really close! There are a couple of things that would need to change, first I'm pretty sure that you cant have a public datatype in a void method, but I might be wrong. Instead, I'd create the random number variable with all of your other variables. I'm also pretty sure you dont need to use Unity.$$anonymous$$athematics for a random number if that is what you were using it for. For the random number, use
yourVariableHere = Random.Range($$anonymous$$, max); hopefully, that helps!