I need the player to temporarily see a pitch black screen with nothing but UI text. Disabling the camera doesn’t work for a number of reasons, is there another way? It is essential for my player to remain in the current level, in their current position, and they must be able to hear as normal. Any help appreciated.
you could use overlays, a background, or an effect that darkens your screen maybe change the lighting you could try some of these
You can apply the same logic of this post in your case.
Here is the same code adjusted to your case:
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class ChangeToDark : MonoBehaviour
{
[Header("Post Processing")]
public VolumeProfile volumeProfile;
private float intensity;
private ColorAdjustments colorAdjustments;
[Header("Blinding")]
public float maxBrightness = 0f;
public float minBrightness = -10f;
public float changeSpeed = 30f;
[SerializeField] private bool changeBrightness; // this doesnt need to be serialized because you will probably end up setting the bool in your script.
private void Start()
{
volumeProfile.TryGet(out colorAdjustments);
}
private void Update()
{
if (changeBrightness)
DarkenScreen();
else if (!changeBrightness)
BrightenScreen();
}
private void BrightenScreen()
{
if (colorAdjustments.postExposure.value >= maxBrightness)
{
colorAdjustments.postExposure.value = maxBrightness; // caps the overflow due to time.deltatime
return;
}
intensity += Time.deltaTime * changeSpeed;
colorAdjustments.postExposure.value = intensity;
}
private void DarkenScreen()
{
if (colorAdjustments.postExposure.value <= minBrightness)
{
colorAdjustments.postExposure.value = minBrightness;// caps the overflow due to time.deltatime
return;
}
intensity -= Time.deltaTime * changeSpeed;
colorAdjustments.postExposure.value = intensity;
}
}
You would have to get a reference to your canvas and use SetActive(false) on it.
(This only works in URP, let me know if you have any problems setting it up
Edit: I just noticed, this topic is almost 9 years old, but I hope I will help future people!)