I have made a flashlight script following mikay on youtube but when I press F nothing happens and the light is on when it should be off at the start what is wrong heres the script
using UnityEngine;
using System.Collections;
public class Flashlight : MonoBehaviour
{
public Light FlashLightObject;
public float Batterypower = 1000.0f;
void Start()
{
FlashLightObject.enabled = false;
}
void Update ()
{
//on/off
if(Input.GetKeyDown(KeyCode.F))
{
if(FlashLightObject.enabled == false){
FlashLightObject.enabled = true;
}
else
{
FlashLightObject.enabled = false;
}
//power management
if (FlashLightObject.enabled == true)
{
Batterypower -= 1.0f;
}
// no power
if (Batterypower <= 0)
{
FlashLightObject.enabled = false;
Batterypower = 0;
}
}
}
i have assigned the light in unity but as i said its on when is should be off and pressing F does nothing
ps. i mannaged to fix it but now i missed a = on if(FlashLightObject.enabled == false){