Random time for different objects from one script

Hi! I’m trying to make simple action script for multiple objects. I want it to give random timing for every object attached. But for now it activates all objects at once and at the lowest given range. I believe there is some way to make it work as i want. Or should i make like 20-30 scripts for each object?

public class ObjectDrop : MonoBehaviour
{
    float passTime;
    new MeshRenderer renderer;
    Rigidbody rb;
    void Start()
    {
        rb = this.GetComponent<Rigidbody>();
        rb.useGravity = false;
        renderer = GetComponent<MeshRenderer>();
        renderer.enabled = false;
    }
    void Update()
    {
        passTime = Random.Range(3.7f, 11.11f);

        if (Time.time > passTime)
        {
            rb.useGravity = true;
            renderer.enabled = true;
        }
        
    }
}

1 Answer

1

Hello @KvarDL,

You are defining the value of passTime in the Update method, in order word at every frame it will change the value so end up with a very low value that will make the condition true. So you should define the value of passTime only once (for example in the Start function)