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

Menu background time activated animations help

Discussion in 'Scripting' started by Andulvar, Feb 15, 2013.

  1. Andulvar

    Andulvar

    Joined:
    Feb 15, 2013
    Posts:
    6
    hey, i jsut wanted to repost as i got the menu from the mate, i put in my code, changed a few things so it would start, had a quick search on how to start particle emitters(just so i know the timer works, but none of it seems to be doing anything, is it something wrong with how it checks, or maybe the time itself, or the emitter.. please help!

    Code (csharp):
    1. #pragma strict
    2.  
    3. private var MenuTime : byte;
    4. private var Intro : boolean = false;
    5. private var Mid : boolean = false;
    6. private var Finale : boolean = false;
    7. private var MenuEnd : boolean = false;
    8.  
    9. function Start () {
    10.  
    11. }
    12.  
    13. function Update () {
    14. MenuTime += Time.deltaTime;         //Makes the variable MenuStart into real seconds.
    15.     if (MenuTime >= 20) {               //Checks the time of the Menu
    16.     MenuTime = 0;                       //Resets Menu Time back to 0
    17.     MenuEnd = true;                     //Makes var True
    18.    
    19.         if (MenuTime==5) {                  //Checks the time  
    20.         Intro = true;                      
    21.        
    22.             if (MenuTime==10) {
    23.             Mid = true;
    24.            
    25.                 if (MenuTime==15) {
    26.                 Finale = true;
    27.                 }
    28.             }
    29.         }
    30.     }
    31. }
    32.  
    33. function IntroAnim () {
    34. Intro = true;
    35. gameObject.particleEmitter.emit = true;
    36. }
    37.  
    38. function MidAnim () {
    39. Mid = true;
    40.  
    41. }
    42.  
    43. function FinaleAnim () {
    44. Finale = true;
    45.  
    46. }
    47. function MenuEndCheck () {
    48.     MenuEnd = true;
    49.     Intro = false;
    50.     Mid = false;
    51.     Finale = false;
    52.     MenuEnd = false;
    53.    
    54. }
     
  2. PaulR

    PaulR

    Joined:
    Nov 14, 2012
    Posts:
    43
    Your logic is flawed. Like
    Code (csharp):
    1.  
    2. if (MenuTime >= 20) {               //Checks the time of the Menu
    3.  
    4.     MenuTime = 0;                       //Resets Menu Time back to 0
    5.     MenuEnd = true;                     //Makes var True    
    6.  
    7.         if (MenuTime==5) {            
    8.  
    The outer if - it's only true if MenuTime is >=20 (so no point checking to see if it's 5 inside!). Then you set it to 0, so it will always be 0 when inside the outer if. On top of that, you're doing exact float value comparison... You should use approximate comparisons for float numbers.