Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

my time.time is not working anyone know why

Discussion in 'Scripting' started by switchluts, Jan 7, 2020.

  1. switchluts

    switchluts

    Joined:
    Mar 18, 2019
    Posts:
    45
    here's the script

    Code (CSharp):
    1.  
    2. public float invis = 2.0f;
    3.     private float vis = 0.0f;
    4. //I've set nextinvis to a higher number didn't help
    5.     public float nextinvis = 2.0f;
    6.     private float nextvis = 0.0f;
    7. void Update()
    8.     {
    9.         spawnWait = Random.Range(spwanMostWait, spawnLeastWait);
    10.  
    11.  
    12.         vis = Time.time + invis;
    13.  
    14.         if (Time.time > vis)
    15.         {
    16.  
    17.            ToggleAllTargets(false);
    18.  
    19.         }
    20.         nextvis = Time.time + nextinvis;
    21.         if (Time.time > nextvis)
    22.         {
    23.            
    24.             ToggleAllTargets(true);
    25.  
    26.         }
    27.  
    28.     }
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,748
    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.
     
    JeffDUnity3D likes this.
  3. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,835
    "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)
     
  4. switchluts

    switchluts

    Joined:
    Mar 18, 2019
    Posts:
    45
    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
     
  5. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,835
    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.