Flashlight problems
I have 2 flashlights in my game, 1 is the player flashlight with a script, other have no script but have animation. When i toggle the player flashlight to off the other flashlight is getting turned on, when i turn the player flashlight on the other flashlight turns off. Its not supposed to do that.
If it helps here is the flashlight code
var flashlightOn : boolean = false;
var button : KeyCode;
function Update ()
{
//Checks if the boolean is true or false.
if(flashlightOn == true)
{
GetComponent.<Light>().intensity = 1;//If the boolean is true, then it sets the intensity to what ever you want.
} else {
if(flashlightOn == false)
{
GetComponent.<Light>().intensity = 0;//If the boolean is false, then it sets the intensity to zero.
}
}
//Checks if the F key is down and whether the boolean is on or off.
if(Input.GetKeyDown(button) && flashlightOn == false)
{
flashlightOn = true; //If the f key is down and the boolean is false, it sets the boolean to true.
} else {
if(Input.GetKeyDown(button) && flashlightOn == true)
{
flashlightOn = false;//If the f key is down and the boolean is true, it sets the boolean to false.
}
}
}
Tested script and it works as expected. As the script only influences Light components directly on the script's gameobject. The other light's gameobject must have a script on it. Unless this is something weird going on with mixing c# and js.
I found out what the error was. The second light needed a high render priority.
Answer by SentokaioStudios · Jul 13, 2021 at 03:17 AM
Using "GetComponet." will get ALL the objects at the scene that have the "light" component. Create a var "Light" (without the quotation marks) and at the editor, attach your player light to it! @$anonymous$
Your answer
Follow this Question
Related Questions
(Newbie) Optimize this android LED-toggle? 0 Answers
Advanced Flashlight Script Issues 1 Answer
Basic flashlight effect 3 Answers
Flashlight (spot light) doesn't work the way I want it to 1 Answer
Flashlight battery 1 Answer