Advertisement
Guest User

ThermalController.cs

a guest
Dec 17th, 2019
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Rendering.PostProcessing;
  5.  
  6. public class ThermalController : MonoBehaviour
  7. {
  8.     public Shader ThermalShader;
  9.     float IntensityThermal;
  10.     bool thermal;
  11.     [SerializeField]
  12.     PostProcessVolume postProcessVolume;
  13.     Camera cam;
  14.     // Start is called before the first frame update
  15.     void Start()
  16.     {
  17.         cam = GetComponent<Camera>();
  18.         cam.enabled = false;    
  19.     }
  20.  
  21.     // Update is called once per frame
  22.     void Update()
  23.     {
  24.         if (Input.GetKeyDown(KeyCode.T))
  25.         {
  26.             thermal = !thermal;
  27.             SwitchThermal(thermal);
  28.         }
  29.     }
  30.  
  31.     void SwitchThermal(bool thermalB)
  32.     {
  33.         if (thermalB)
  34.         {
  35.             cam.enabled = true;
  36.             IntensityThermal = 1;
  37.             if(postProcessVolume != null)
  38.             {
  39.                 postProcessVolume.weight = IntensityThermal;
  40.             }
  41.             cam.SetReplacementShader(ThermalShader, "ThermalVision");
  42.            
  43.         }
  44.         else
  45.         {
  46.             cam.enabled = false;
  47.             IntensityThermal = 0;
  48.             if (postProcessVolume != null)
  49.             {
  50.                 postProcessVolume.weight = IntensityThermal;
  51.             }
  52.             cam.ResetReplacementShader();          
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement