I have been trying to get my flashlight script to work yet, it keeps saying there is no light attach to the game object.
Here is the script:
using UnityEngine;
using System.Collections;
public class Flashlight : MonoBehaviour
{
public float a;
public float b;
public float c;
public float d;
public int batLevel;
public Light Flashlight;
public bool isOn;
public float timer;
void Start()
{
Flashlight = GetComponent<Light>();
batLevel = 101;
minusBat();
isOn = true;
}
void minusBat()
{
if (isOn)
{
batLevel -= 1;
}
}
void Update()
{
if (timer >= 0)
{
if (isOn)
{
timer -= Time.deltaTime;
}
}
if (timer <= 0)
{
timer = 5;
minusBat();
}
if (Input.GetKeyUp(KeyCode.F))
{
Flashlight.enabled = !Flashlight.enabled;
if (!isOn)
{
isOn = true;
}
else
{
isOn = false;
}
}
if (batLevel == 0)
{
batLevel = 0;
Flashlight.enabled = false;
isOn = false;
}
}
void OnGUI()
{
GUI.Box(new Rect(0, Screen.height / 1.21f, Screen.width / 6.16f, Screen.height / 19.58f), batLevel.ToString());
}
}
can someone tell me what i can do to fix this?