CapsuleController.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using UnityEngine;
  2. using VolumetricFogAndMist2;
  3. namespace VolumetricFogAndMist2.Demos {
  4. public class CapsuleController : MonoBehaviour {
  5. public VolumetricFog fogVolume;
  6. public float moveSpeed = 10f;
  7. public float fogHoleRadius = 8f;
  8. public float clearDuration = 0.2f;
  9. public float distanceCheck = 1f;
  10. Vector3 lastPos = new Vector3(float.MaxValue, 0, 0);
  11. void Update() {
  12. float disp = Time.deltaTime * moveSpeed;
  13. // moves capsule with arrow keys
  14. if (Input.GetKey(KeyCode.LeftArrow)) {
  15. transform.Translate(-disp, 0, 0);
  16. } else if (Input.GetKey(KeyCode.RightArrow)) {
  17. transform.Translate(disp, 0, 0);
  18. }
  19. if (Input.GetKey(KeyCode.UpArrow)) {
  20. transform.Translate(0, 0, disp);
  21. } else if (Input.GetKey(KeyCode.DownArrow)) {
  22. transform.Translate(0, 0, -disp);
  23. }
  24. // do not call SetFogOfWarAlpha every frame; only when capsule moves
  25. if ((transform.position - lastPos).magnitude > distanceCheck) {
  26. lastPos = transform.position;
  27. fogVolume.SetFogOfWarAlpha(transform.position, radius: fogHoleRadius, fogNewAlpha: 0, duration: clearDuration);
  28. }
  29. }
  30. }
  31. }