Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity camera fade to black

using UnityEngine;
 
public class FadeCamera : MonoBehaviour
{
    public AnimationCurve FadeCurve = new AnimationCurve(new Keyframe(0, 1), new Keyframe(0.6f, 0.7f, -1.8f, -1.2f), new Keyframe(1, 0));
 
    private float _alpha = 1;
    private Texture2D _texture;
    private bool _done;
    private float _time;
 
    public void Reset()
    {
        _done = false;
        _alpha = 1;
        _time = 0;
    }
 
    [RuntimeInitializeOnLoadMethod]
    public void RedoFade()
    {
        Reset();
    }
 
    public void OnGUI()
    {
        if (_done) return;
        if (_texture == null) _texture = new Texture2D(1, 1);
 
        _texture.SetPixel(0, 0, new Color(0, 0, 0, _alpha));
        _texture.Apply();
 
        _time += Time.deltaTime;
        _alpha = FadeCurve.Evaluate(_time);
        GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), _texture);
 
        if (_alpha <= 0) _done = true;
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# write iformfile 
Csharp :: c# singleton 
Csharp :: string.QueryString c# 
Csharp :: class in c# 
Csharp :: get min date in list c# 
Csharp :: unity singleton 
Csharp :: wpf datagrid get selected items 
Csharp :: HTTP Error 500.35 - ASP.NET Core does not support multiple apps in the same app pool 
Csharp :: finding values in the registry 
Csharp :: c# gettype 
Csharp :: c# shorthand if statement without else 
Csharp :: remove duplicates in the list using linq 
Csharp :: c# check if object is of any generic type 
Csharp :: rotation 
Csharp :: how to add skybox in unity 
Csharp :: setting the parent of a transform which resides in a prefab 
Csharp :: tailwind right 
Csharp :: read json from assets c# 
Csharp :: What are logic gates? 
Csharp :: Options Pattern startup.cs configuration 
Csharp :: ontriggerenter2d 
Csharp :: linq select max value from list 
Csharp :: only specific columns in Linq 
Csharp :: get first number in string C# 
Csharp :: c# code to check anagram 
Csharp :: how to make a system to check if i see certain object in unity 
Csharp :: how to iterate a generic list in c# 
Csharp :: generate a dropdown list from array data using razor .net mvc 
Csharp :: how to pass function as paraemter of another function pythpn 
Csharp :: how create two database conction in laravel 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =