my time.time is not working anyone know why

here’s the script

public float invis = 2.0f;
    private float vis = 0.0f;
//I've set nextinvis to a higher number didn't help
    public float nextinvis = 2.0f;
    private float nextvis = 0.0f;
void Update()
    {
        spawnWait = Random.Range(spwanMostWait, spawnLeastWait);


        vis = Time.time + invis;

        if (Time.time > vis)
        {

           ToggleAllTargets(false);

        }
        nextvis = Time.time + nextinvis;
        if (Time.time > nextvis)
        {
           
            ToggleAllTargets(true);

        }

    }

You generally need to tell us what “not working” means - what is it supposed to do, and what does it do instead?

I can tell you right now though, that Time.time will never be greater than vis, because you’ve just set vis to Time.time. Same thing with nextvis a few lines later. So that’s probably a problem.

1 Like

“Not working” is not a description of a problem. Do you get an error message? Does it freeze the program? Does your computer catch fire?

A good debugging thread should include:

  • What you want to have happen

  • How you tried to make it happen

  • What actually happened instead (and how that’s different)

I’m trying to make the ToggleAllTargets go from through to false and back every 2 seconds. it doens’t do anything but a weird thing is if I change the value to 6 and then back to 2 while playing it works perfectly

Update() gets called every frame. So right now, every single frame, you are changing the value of “vis” to be the current time plus the value of “invis”. Unless “invis” is negative, that means that “vis” will never be less than the current time.