Search Unity

timer goes below and doest execute script

Discussion in 'Scripting' started by thebest07111, Sep 22, 2014.

  1. thebest07111

    thebest07111

    Joined:
    Jan 20, 2014
    Posts:
    129
    hello.
    i have this code
    Code (CSharp):
    1.     if(Pylon.strikecheck == true)
    2.     {
    3.         Spawner.timer1 -= 1 * Time.deltaTime;
    4.         if (Spawner.timer1 <=0)
    5.         {
    6.             //timer neit gelijk doen
    7.             if (Spawner.pylonnen == 0)
    8.             {
    9.                 Debug.Log("strike");
    10.                 GUI.Box(new Rect(Screen.width - 100, 0, 100, 50), "STRIKE!!!");
    11.                
    12.             }
    13.             else if (Spawner.pylonnen > 0)
    14.             {
    15.                 Debug.Log("2e trow");
    16.                 Pylon.nogeenkeerschieten = true;
    17.                
    18.             }
    19.         }
    20.  
    21.     }
    But for some reason when Spawner.timer goes below 0 it doest say STRIKE and it should say strike because i set the Spawner.pylonnen to 0 for testing.
    Can someone helpt
     
  2. Limeoats

    Limeoats

    Joined:
    Aug 6, 2014
    Posts:
    104
    Is it printing "2e trow" or is it simply returning without printing anything?
    If nothing is getting printed at all, then either pylon.strikecheck is not true when this code is getting executed, or something strange is happening to your timer1 variable (maybe it is getting re-initialized to its starting value each time around the loop for some reason).
    If "2e trow" is getting printed, then Spawner.pylonnen is something greater than 0.
     
  3. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    You've already had a thread (here) about the issue. In this thread you had posted the code which runs before this condition turns true and people have posted about the problems.

    In case you haven't change the code yet, you should follow the suggestions in your old thread.
     
  4. thebest07111

    thebest07111

    Joined:
    Jan 20, 2014
    Posts:
    129
    I fixed it
    for some reason the timer keeps getting back to its original seconds
    but i fixed it now