Hi, I’m currently trying to use the Random.Range method to generate a random number that will tell the dropper to turn on gravity, render, and then drop.
I’m able to verify that the random number is generated and instantiated through my variable num through Debug.Log. When I use it in my if statement “if (Time.time > num)” instead of a SerializedField, I find that my dropper ignores the Randomly generated time and drops instantly.
How can I make it so that it follows the time created with Random?
public class Dropper : MonoBehaviour
{
MeshRenderer renderer;
Rigidbody rigidBody;
int num;
// Update is called once per frame
void Start()
{
renderer = GetComponent<MeshRenderer>();
rigidBody = GetComponent<Rigidbody>();
renderer.enabled = false;
rigidBody.useGravity = false;
int num = Random.Range(3, 10);
}
void Update()
{
Timer(num);
}
void Timer(int num)
{
if (Time.time > num)
{
rigidBody.useGravity = true;
renderer.enabled = true;
}
}
}
Thanks!