- Home /
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;
}
}
The actual issue seems to be that "NormalVision" seems to be missing. Where do you assign those variables?
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;
}
}
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!
Answer by KiraSensei · Jul 08, 2014 at 01:44 PM
Try this :
function Start ()
{
NormalVision.enabled = true;
NightVision.enabled = false;
}
I dont see how that helps. I kindoff need my code but just rewritten to be able to toggle, not only toggling once.
So tell us what is the real problem and is not happening next time.
Your answer
Follow this Question
Related Questions
UI Button ON/Off 3 Answers
On/off switch from server to clients live 1 Answer
How can i make my Timer script start and pause only when something certain is activated? 2 Answers
particle emitter on/off using the left mouse button 1 Answer
How to turn on a light by pressing and after few seconds turn it off 1 Answer