Hi!
Anybody know how to separate the fog on certain area. for example over specific mesh.
Thanks!
Create a cube in your scene, put this script on it. Then make sure your character/camera has a rigidbody. The fog should switch while the rigidbody is inside the cube/BoxCollider. Disable the Renderer on the cube if you wish.
using UnityEngine;
using System.Collections;
public class ChangeFog : MonoBehaviour {
public Color fogColor;
private Color originalFogColor;
// Use this for initialization
void Start () {
RenderSettings.fog = true;
if (GetComponent<Collider>() == null)
gameObject.AddComponent<BoxCollider>();
}
void OnTriggerEnter() {
RenderSettings.fogColor = fogColor;
}
void OnTriggerExit() {
RenderSettings.fogColor = originalFogColor;
}
}
I’m only storing fogColor here, but you can store all kinds fog properties from RenderSettings. You can also do cool things like Color.Lerp to change fogColor over time.