DemoMultipleFogAreas.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace VolumetricFogAndMist {
  4. public class DemoMultipleFogAreas : MonoBehaviour {
  5. void Update() {
  6. if (Input.GetKeyDown(KeyCode.C)) {
  7. CreateCloud();
  8. } else if (Input.GetKeyDown(KeyCode.B)) {
  9. CreateBoxFog();
  10. } else if (Input.GetKeyDown(KeyCode.X)) {
  11. VolumetricFog.RemoveAllFogAreas();
  12. }
  13. }
  14. /// <summary>
  15. /// Create a random cloud shape fog area near camera position.
  16. /// </summary>
  17. void CreateCloud() {
  18. Vector3 position = Camera.main.transform.position + Camera.main.transform.forward * 100 + Random.insideUnitSphere * 50f;
  19. if (position.y<10) position.y = 10f;
  20. float radius = Random.value * 50f + 85f;
  21. VolumetricFog fog = VolumetricFog.CreateFogArea(position, radius);
  22. fog.color = new Color(0.6f,0.57f,0.5f,1f);
  23. }
  24. /// <summary>
  25. /// Create a random box-shape fog area near camera position.
  26. /// </summary>
  27. void CreateBoxFog() {
  28. Vector3 position = Camera.main.transform.position + Camera.main.transform.forward * 100 + Random.insideUnitSphere * 50f;
  29. if (position.y<10) position.y = 10f;
  30. Vector3 size = new Vector3(Random.value * 50f + 35f, Random.value * 10f + 15f, Random.value * 50f + 35f);
  31. VolumetricFog fog = VolumetricFog.CreateFogArea(position, size);
  32. fog.color = new Color(0.6f,0.57f,0.5f,1f);
  33. fog.noiseScale = 2f;
  34. }
  35. }
  36. }