Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Jan 26, 2016 at 11:16 AM by Daniel_Zabojca for the following reason:

The question is answered, right answer was accepted.

avatar image
0
Question by Daniel_Zabojca · Jan 21, 2016 at 12:35 PM · shader3dplayerinteractionkey pressed

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Daniel_Zabojca · Jan 26, 2016 at 11:16 AM 0
Share

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.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

50 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges