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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Countdown Fade in - how?

Discussion in 'Immediate Mode GUI (IMGUI)' started by CodeNashor, Nov 2, 2014.

  1. CodeNashor

    CodeNashor

    Joined:
    Jan 6, 2014
    Posts:
    18
    Hello guys!

    Currently I am working on a racing game with a sphere (like 'I've got some balls', awesome game btw ;) )
    Now i want to make a starting countdown before each level (3..,2...,1..., GO!).

    I made it so far, but i want to fade it in. Like the '3' is in the middle of the screen and becoming bigger and bigger, then '2' same thing, and so on.

    Hope you know what i mean, i dont know how to do it. I am just finding things like 'fading in scene'.

    In the near future, i want to use transparency textures for each digit and i want to fade them in AND increasing size in an amount of time (like i mentioned before).

    Would be awesome if you could give me some tips, how i could do this.
     
  2. CodeNashor

    CodeNashor

    Joined:
    Jan 6, 2014
    Posts:
    18
    Okay i made it, pretty simple.

    Code (CSharp):
    1. function OnGUI(){
    2.     // Texture 3...
    3.     if(countdown == 3){
    4.         countdown_material = countdown_material_3;
    5.     }
    6.  
    7.     // Texture 2...
    8.     if(countdown == 2){
    9.         countdown_material = countdown_material_2;
    10.     }
    11.  
    12.     // Texture 1...
    13.     if(countdown == 1){
    14.         countdown_material = countdown_material_1;
    15.     }
    16.  
    17.     if(countdown > 0){
    18.         scaleX = (Time.time % 1) * 400;
    19.         scaleY = (Time.time % 1) * 400;
    20.         GUI.Label(Rect(Screen.width / 2 - scaleX/2, Screen.height /2 - scaleY/2, scaleX, scaleY), countdown_material.mainTexture);
    21.     }
    22.  
    23. ....
    24. }
    Works great, 'countdown_material_x' are the textures with the digits (3,2,1). 'Time.time % 1' resets each second the size and location. So each second, each digit getting bigger and bigger from the middle of the screen till the next second isn't reached.

    countdown gets increased with InvokeRepeating("startCountdown", 1, 1.0); at Start()

    Hope i can help some guys, who has the same question ;)

    //Edit

    If you build a 'Restart Lvl' on Backspace, 'Time.time' won't work in this way with the countdown timer, you have to check / reset / save milliseconds of Time.time or using your own Timer.
     
    Last edited: Nov 2, 2014