using UnityEngine; using System.Collections; namespace VolumetricFogAndMist { public class DemoMultipleFogAreas : MonoBehaviour { void Update() { if (Input.GetKeyDown(KeyCode.C)) { CreateCloud(); } else if (Input.GetKeyDown(KeyCode.B)) { CreateBoxFog(); } else if (Input.GetKeyDown(KeyCode.X)) { VolumetricFog.RemoveAllFogAreas(); } } /// /// Create a random cloud shape fog area near camera position. /// void CreateCloud() { Vector3 position = Camera.main.transform.position + Camera.main.transform.forward * 100 + Random.insideUnitSphere * 50f; if (position.y<10) position.y = 10f; float radius = Random.value * 50f + 85f; VolumetricFog fog = VolumetricFog.CreateFogArea(position, radius); fog.color = new Color(0.6f,0.57f,0.5f,1f); } /// /// Create a random box-shape fog area near camera position. /// void CreateBoxFog() { Vector3 position = Camera.main.transform.position + Camera.main.transform.forward * 100 + Random.insideUnitSphere * 50f; if (position.y<10) position.y = 10f; Vector3 size = new Vector3(Random.value * 50f + 35f, Random.value * 10f + 15f, Random.value * 50f + 35f); VolumetricFog fog = VolumetricFog.CreateFogArea(position, size); fog.color = new Color(0.6f,0.57f,0.5f,1f); fog.noiseScale = 2f; } } }