- Home /
How do you make a scene darker?
Good day everyone!
I'm working on a 3d game in which the player wakes up in a room (specifically, their bedroom), and after some time, I want the electricity to cut off, and the house to get dark. How can I achieve this? This will be my first time diving into proper lighting so I'm not sure how to approach this. :D I'd really appreciate any help and suggestions!
Answer by Llama_w_2Ls · Feb 19, 2021 at 02:15 PM
Disabling directional lights may cause the effect you want, but I prefer using black dense fog. It creates a sense of not being able to see things in the distance, but able to see things closer to you.
You can do this manually by going into your lighting settings and enabling fog, setting the color to black and increasing the density, and then enabling/disabling it when needed by using render settings. See doc here RenderSettings.Fog
Hello! Thank you for your reply, I'll definitely try this out. :) I have one question though. Should I just create an empty game object and attach the script to that?
You could use an empty GO to do this, called a lighting controller or something. It's up to you.
I was able to get it to work and (almost) achieve the result I want. I think in addition to using fog, I'll also disable the directional lights to really give it that dark ambience. Thank you very much for your suggestion!
Answer by badiiiro · Feb 19, 2021 at 02:11 PM
Hey, maybe a script like this can help you achieve what you want:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TurnLightAfterX : MonoBehaviour
{
[Header("Light Manager Settings:")]
[Tooltip("You can drag here your directional light")] public Light mainLight;
[SerializeField] private float turnLightAfter = 60f;
private void Start()
{
Debug.Log("Turning the main light off");
mainLight.enabled = false;
StartCoroutine(TurnMainLight());
}
IEnumerator TurnMainLight()
{
Debug.Log("Turning the main light on after" + turnLightAfter));
yield return new WaitForSeconds(turnLightAfter);
mainLight.enabled = true;
}
}