如何以编程方式 enable/disable 相机效果?

How to enable/disable cameras' effects programmatically?

我的场景中有一个主摄像机,上面有 Sun Shafts (Script) ImageEffect。

[![在此处输入图片描述][1]][1]

(我正在使用中世纪环境资产。)

我想在主相机到达特定坐标时以编程方式禁用此效果。

Please kkep in mind, that the script I'd like to disable is a .js script.

所以这是我的代码:

foreach(Camera c in GameObject.FindObjectsOfType(typeof(Camera))) 
{
    if ((c.name == "Main Camera"))
    {
        if ((c.transform.position.x < -10))
        {
        //Disable Sun Shafts effect
        }
    }
}

如何以编程方式禁用 Sun Shafts 效果?

如果你 google "Unity3d disable a component" 你会立即找到答案

https://unity3d.com/learn/tutorials/modules/beginner/scripting/enabling-disabling-components

yourComponent.enabled = false;

例如,最好的 Unity 工程师之一的完美回答,基本上是完美的

http://answers.unity3d.com/answers/26849/view.html

注意例子 "If you see a checkbox in the Inspector, you can enable or disable it."

请注意,在 Whosebug 上,您无法通过编辑问题来更改问题 -- 请随时提出新问题。想问多少就问多少。