JamesMakesGames

NightVisionController

Jun 22nd, 2022
1,887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.Rendering.PostProcessing;
  3.  
  4. [RequireComponent(typeof(PostProcessVolume))]
  5. public class NightVisionController : MonoBehaviour
  6. {
  7.     [SerializeField] private Color defaultLightColour;
  8.     [SerializeField] private Color boostedLightColour;
  9.  
  10.     private bool isNightVisionEnabled;
  11.  
  12.     private PostProcessVolume volume;
  13.  
  14.     private void Start()
  15.     {
  16.         RenderSettings.ambientLight = defaultLightColour;
  17.  
  18.         volume = gameObject.GetComponent<PostProcessVolume>();
  19.         volume.weight = 0;
  20.     }
  21.    
  22.     private void Update()
  23.     {
  24.         if (Input.GetKeyDown(KeyCode.N))
  25.         {
  26.             ToggleNightVision();
  27.         }
  28.     }
  29.  
  30.     private void ToggleNightVision()
  31.     {
  32.         isNightVisionEnabled = !isNightVisionEnabled;
  33.  
  34.         if (isNightVisionEnabled)
  35.         {
  36.             RenderSettings.ambientLight = boostedLightColour;
  37.             volume.weight = 1;
  38.         }
  39.         else
  40.         {
  41.             RenderSettings.ambientLight = defaultLightColour;
  42.             volume.weight = 0;
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment