Darken effect, how to achieve this

I’ve got a simple 2d platformer. This game allows the player to right click to get some sort of command interface to issue commands to his minions. As he activates this, time slows down and he can direct minions to solve puzzles.

However, the longer he takes in the command interface, the darker the background should be, so as long as the command interface is active, the scene, all parts, except the command interface it self, should become darker and darker until it’s completely black.

I thought about doing something like placing a transparent mesh or such between the scene and the command interface and then slightly slowly darken it over time, making it less transparent, but have not been able to accomplish that so far. Anyone have an idea on how to do this?

If you will put something between camera and scene, you can place black sprite. Set its alfa to zero (in inspector: sprite rendere - color- a). And then make script, which change the alfa from zero(invisible) to 255(visible).
Something like this (script should be added to black sprite):

using UnityEngine;
using System.Collections;

public class AlfaTest : MonoBehaviour
{
    SpriteRenderer sr;

    // Use this for initialization
    void Start ()
    {
        sr = GetComponent <SpriteRenderer> ();
    }
 
    // Update is called once per frame
    void Update ()
    {
        Color color = sr.color;
        color.a += Time.deltaTime*0.1F;
        sr.color = color;
    }
}
1 Like