The question is answered, right answer was accepted.
Unity 3D #C Nightvision does not want to switch on or off.
Hello everyone,
I got a question and I need your help. To the point : I have assembled 2 scripts. (shown down) And I want to 'toggle' my night vision with the V button on the keyboard. But somehow it does not want to work, and I do not know why. I know that the script gets enabled and disabled. ( Shader works fine.) So, can anyone explain to me and maybe help me fix this annoying problem?
1 :
     using UnityEngine;
       using System.Collections;
        public class NightVision : MonoBehaviour
    {
 public bool bright = true;
 public float brightness = 2.0f;
 public Shader nightvisionShader;
 public void OnEnable()
 {
   
         nightvisionShader = Shader.Find("NVision");
     Debug.Log("Found!");
   
 }
 public void OnPreCull()
 {
     if (bright)
     {
         Shader.SetGlobalFloat("_Brightness", brightness);
         Shader.SetGlobalFloat("_Bright", 1.0f);
         Debug.Log("Found brightness");
         
     }
     else
     {
         Shader.SetGlobalFloat("_Bright", 0.0f);
     }
     if (nightvisionShader)
         transform.GetComponent<Camera>().SetReplacementShader(nightvisionShader, null);
     Debug.Log("Enable NVISION");
 }
  }
2
      using UnityEngine;
       using System.Collections;
    public class Enabler : MonoBehaviour {
 public NightVision Nvision;
 // Use this for initialization
 void Start () {
     Nvision = GetComponent<NightVision>();
 }
 
 // Update is called once per frame
 void Update () {
     if (Input.GetButtonDown("NightVision"))
     {
         Nvision.enabled = true;
         Debug.Log("Enabled NVidia");
     }
     else
  if (Input.GetButtonUp("NightVision"))
     {
         Nvision.enabled = false;
         Debug.Log("Disabled NVidia");
     }
 }
  }
And I want It To toggle night vision with the button V, But it does not work. I am at a complete loss here.
Can someone please help me fix this annoying problem?
Thank you all in advance and have a nice day,
Daniel Nowak Janssen
I found it already,
I made another script that switches between 2 camera's. One with Night vision and the normal. It's quite funny I did not think of it earlier.
Follow this Question
Related Questions
Unty 3D C# Load other scene when bool = true, otherwise perform teleportation as commanded. 1 Answer
Mining from a chunk? - 3d Game Cavern Generation + Player integration 0 Answers
Antichamber-like shader for lights and outline? 0 Answers
Small bug? on ShaderGraph 0 Answers
Teleporting player on key press 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                