• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by mikhailovic · Jul 08, 2014 at 01:40 PM · camerasonoffvisionnight

My night vision wont turn on/off

Hello! I am quite a beginner when it comes to coding, and only grasps the most fundamental. I have created two cameras for my FPC, one with tons of image effects and one with simple vision, and put them both in a Empty game object. I wrote this script: (no hate im a total newb...)

Also i get this error: MissingReferenceException: The variable NormalVision of NightVision doesnt exist anymore.

 var NormalVision : Camera;
 var NightVision : Camera;
 
 
 
 function Start ()
 {
     NormalVision .enabled = true;
     NightVision.enabled = false;
 }
 
 function Update ()
 {
     if (Input.GetKeyDown("f"))
     {
         NormalVision.enabled = false;
         NightVision.enabled = true;
     }
 }

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 christoph_r · Jul 10, 2014 at 10:35 PM 0
Share

The actual issue seems to be that "NormalVision" seems to be missing. Where do you assign those variables?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Olgo · Jul 08, 2014 at 06:21 PM

The issue with your code is that it only sets one to true and one to false every time you hit f, what you want them to do is toggle. To make them toggle, set them to the opposite of what they currently are by using !. Try the following.

     var NormalVision : Camera;
     var NightVision : Camera;
      
     function Start ()
     {
        NormalVision.enabled = true;
        NightVision.enabled = false;
     }
      
     function Update ()
     {
        if (Input.GetKeyDown("f"))
        {
           NormalVision.enabled = !NormalVision.enabled;
           NightVision.enabled = !NightVision.enabled;
        }
     }
  
Comment
Add comment · Show 1 · Share
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 mikhailovic · Jul 10, 2014 at 07:59 PM 0
Share

As NightVision i use a camera with alot of image effects in conjunction with a spotlight, so i just made a easy toggle for the flashlight separately ins$$anonymous$$d, thanks for your answers!

avatar image
0

Answer by KiraSensei · Jul 08, 2014 at 01:44 PM

Try this :

 function Start ()
 {
     NormalVision.enabled = true;
     NightVision.enabled = false;
 }
Comment
Add comment · Show 2 · Share
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 mikhailovic · Jul 08, 2014 at 06:10 PM 0
Share

I dont see how that helps. I kindoff need my code but just rewritten to be able to toggle, not only toggling once.

avatar image KiraSensei · Jul 08, 2014 at 06:48 PM 0
Share

So tell us what is the real problem and is not happening next time.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

turn on and off the render of a child 1 Answer

Getting GUI texture on and off 0 Answers

Turn on/off Script 3 Answers

Turn On and Off Lights Via Script 1 Answer

Particle system turns on when player gets close. 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