是否可以从脚本更改后期处理?

问题描述 投票:0回答:1

我正在制作一款 2D 恐怖游戏,当时我想到了在一些可怕的时刻,色彩效果会沿着屏幕边缘增加,但我不知道该怎么做。您能给出一个用于此目的的脚本示例吗?这样当进入2D碰撞器时,色彩效果会逐渐增强,离开时色彩效果逐渐下降

我是 Unity 的新手,所以我尝试在 YouTube 或其他网站上寻找解决方案,但找不到。_.

这是我找到的一个脚本示例,但我不明白他们的后处理如何取得半音效果并在脚本中指出它

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;

public class ChromaticEffect : MonoBehaviour
{
    public Collider2D triggerCollider;
    public bool isTriggered;
    public PostProcessVolume postProcessVolume;
    public ChromaticAberration chromaticAberration;
    public float maxChromaticIntensity;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision == triggerCollider)
        {
            isTriggered = true;
        }
    }

    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision == triggerCollider)
        {
            isTriggered = false;
        }
    }

    private void Update()
    {
        if (isTriggered)
        {
            chromaticAberration.intensity.value = 
            Mathf.Lerp(chromaticAberration.intensity.value, 
            maxChromaticIntensity, Time.deltaTime);
        }
        else
        {
            chromaticAberration.intensity.value = M 
            athf.Lerp(chromaticAberration.intensity.value, 0f, Time.deltaTime);
        }
    }
}
c# unity-game-engine 2d chromatic
1个回答
0
投票

Afaik,您可以通过例如访问它

var chromaticAberration = postProcessVolume.profile.GetSetting<ChromaticAberration>();

chromaticAberration.intensity = XY;
© www.soinside.com 2019 - 2024. All rights reserved.