我正在做FPS游戏,我有一个被海洋包围的小岛,并且正在使用主相机中的雾在水下编程效果。问题在于,在IDE Unity中此效果可以正确执行,但是在编译游戏和执行.exe文件时,该效果无法发挥,但是在IDE中却不能发挥作用,如前所述。我不知道会发生什么。 我为此功能编写的脚本如下:
public class UnderWaterEffect : MonoBehaviour
{
//This script enables underwater effects. Attach to main camera.
//Define variable
public int underwaterLevel = 7;
public Material noSkybox;
private AudioSource audioClip;
//The scene's default fog settings
private bool defaultFog;
private Color defaultFogColor;
private float defaultFogDensity;
private Material defaultSkybox;
void Start ()
{
this.audioClip = gameObject.GetComponent<AudioSource>();
this.defaultFog = RenderSettings.fog;
this.defaultFogColor = RenderSettings.fogColor;
this.defaultFogDensity = RenderSettings.fogDensity;
this.defaultSkybox = RenderSettings.skybox;
}
public void ApplyDefaultEffect()
{
RenderSettings.fog = this.defaultFog;
RenderSettings.fogColor = this.defaultFogColor;
RenderSettings.fogDensity = this.defaultFogDensity;
RenderSettings.skybox = this.defaultSkybox;
this.audioClip.Stop();
}
public void ApplyEffect() {
//Set the background color
//Camera.main.backgroundColor = new Color(0.22f, 0.64f, 0.77f, 0.6f);
RenderSettings.fog = true;
RenderSettings.fogColor = new Color(0.22f, 0.64f, 0.77f, 0.6f);
RenderSettings.fogDensity = 0.045f;
RenderSettings.skybox = noSkybox;
this.audioClip.Play(0);
}
}
上面的代码被触发器调用,触发器是我放在海洋表面的一个立方体,当与该立方体发生碰撞时,触发器被激活并调用关联脚本的Camera代码,该代码如下:
public class ActivarCamaraAgua : MonoBehaviour
{
public GameObject CameraPlayer;
private void OnTriggerEnter(Collider other)
{
CameraPlayer.SendMessage("ApplyEffect", SendMessageOptions.RequireReceiver);
}
private void OnTriggerExit(Collider other)
{
CameraPlayer.SendMessage("ApplyDefaultEffect", SendMessageOptions.RequireReceiver);
}
}