How to Fade into black and white in a particular scene?
So I have a scene and I want to make the scene black and white (fade into black and white) whenever I Pause my game, and I have got NO FRIKIN Idea how to do it because there is no option to control the amount of black and whiteness(a term that I just invented) in the inspector.
I am no shader guy so please reply as detailed as possible
Answer by unity_21erushbrook · May 11, 2018 at 12:04 AM
Super easy. Make a canvas that covers the entire screen and put an image in it that is just pure black. Then use this script on it to fade from black when it starts.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Fade : MonoBehaviour {
public float FadeRate;
private Image image;
private float targetAlpha;
// Use this for initialization
void Start () {
this.image = this.GetComponent<Image>();
if(this.image==null)
{
Debug.LogError("Error: No image on "+this.name);
}
this.targetAlpha = this.image.color.a;
}
// Update is called once per frame
void Update () {
Color curColor = this.image.color;
float alphaDiff = Mathf.Abs(curColor.a-this.targetAlpha);
if (alphaDiff>0.0001f)
{
curColor.a = Mathf.Lerp(curColor.a,targetAlpha,this.FadeRate*Time.deltaTime);
this.image.color = curColor;
}
}
public void FadeOut()
{
this.targetAlpha = 0.0f;
}
public void FadeIn()
{
this.targetAlpha = 1.0f;
}
}
That just does not work, the image stays black, no Grayscale effect.
Ins$$anonymous$$d of scripting the fade, you could just use an animation.
Then just trigger it whenever you want to pause or resume your game.