how to fade away scene for few seconds

I’m a newbie with Unity. I’m programming a simple game, in which the player has to collect some objects. What I would like to do is that after he collects an object, the scene fades away for few seconds and then the player position is changed. I know how to change the position, I have no idea how to make the fade away effect. I’ve tried using the Image Effect (such as Vortex and Blur) but I’m no able to slowly increment their variables (e.g. angle value for Vortex and blur iteration for blur) so that gives the impression of an animation.

Could someone guide me throw this?

Thank you very much!

hi there,what you are looking for is in the learn section.under animation, or follow survival shooters final tutorial (gameover).

You can play around with coroutines and Color.Lerp, changing the image’s color by a few seconds and then returning it to normal.

Here is a script for you, use it as a base to implement what you really want:

using System.Collections;
using UnityEngine;
using UnityEngine.UI;

public class FadeManager : MonoBehaviour
{
    [SerializeField]
    private Color opaqueColor = Color.black;
    [SerializeField]
    private Color transparentColor = Color.clear;
    [SerializeField]
    private Canvas canvas;
    [SerializeField]
    private Image image;

    private void Start()
    {
        canvas.enabled = false;
    }

    public void Fade(float duration)
    {
        duration *= 0.5f;

        if (duration <= 0)
        {
            duration = Time.deltaTime / 2;
        }

        StartCoroutine(IFade(duration));
    }

    private IEnumerator IFade(float duration)
    {
        canvas.enabled = true;

        image.color = opaqueColor;

        for (float t = 0.0f; t < 1.0f; t += Time.deltaTime / duration)
        {
            image.color = Color.Lerp(opaqueColor, transparentColor, t);

            yield return null;
        }

        image.color = transparentColor;

        for (float t = 0.0f; t < 1.0f; t += Time.deltaTime / duration)
        {
            image.color = Color.Lerp(transparentColor, opaqueColor, t);

            yield return null;
        }

        image.color = opaqueColor;

        canvas.enabled = false;
    }
}

I didn’t tested the code, but it should work.