user3421905
user3421905

Reputation: 51

Create effect dark and light when game start in unity

I am new in unity, i need to create a effect when my game is started:

Please teach me how i can do it, Thanks so much.

Upvotes: 0

Views: 711

Answers (2)

Josh
Josh

Reputation: 220

Here's what I use. I create a pixel texture and use the GUI system to ensure it'll be drawn before everything in the scene. I actually use a display manager to control the order GUI elements are drawn to make sure the overlay is in front of other gui elements.

using UnityEngine;
using System.Collections;

public class Overlay : MonoBehaviour {

    //----------------------------------------------------------------------------------------------------//

    [SerializeField]
    private Color                                           screenColor         = Color.black;
    [SerializeField]
    private float                                           fadeSpeed           = 0.5f;

    //----------------------------------------------------------------------------------------------------//

    static private Texture2D                        overlay;
    static private bool                                 fadeOverlay;
    static private bool                                 fadeOverlayIn;

    //----------------------------------------------------------------------------------------------------//

    public void Awake() {
        //Setup the values for the fading overlay.
        overlay = new Texture2D( 1, 1 );
        overlay.SetPixel( 0, 0, screenColor );
        overlay.Apply();
        fadeOverlay = true;
        fadeOverlayIn = false;
    }

    public void Update() {
        if ( fadeOverlay ) {
            if ( fadeOverlayIn ) {
                screenColor.a += Time.deltaTime * fadeSpeed;
                if ( screenColor.a >= 1 ) {
                    fadeOverlay = false;
                }
            } else {
                screenColor.a -= Time.deltaTime * fadeSpeed;
                if ( screenColor.a <= 0 ) {
                    fadeOverlay = false;
                }
            }
            overlay.SetPixel( 0, 0, screenColor );
            overlay.Apply();
        }
    }

    public void OnGUI() {
        if ( fadeOverlayIn || fadeOverlay ) {
            GUI.DrawTexture( Camera.main.pixelRect, overlay );
        }
    }

    static public void Toggle() {
        fadeOverlay = true;
        fadeOverlayIn = !fadeOverlayIn;
    }

    //----------------------------------------------------------------------------------------------------//

}

Upvotes: 1

Rasa Mohamed
Rasa Mohamed

Reputation: 892

1st you have to add Light on your scene from GameObject Menu in unity. If you need On Off that light just add the Javascript to your light. Lot of ways to do this Google it and easy to find.

var times : float;
function Start () {
light.intensity =0;
}

function Update () {
times += Time.deltaTime; // just I added time.
if (times > 5) // or Here you can use Press key events....
 light.intensity =8;
}

Upvotes: 1

Related Questions