So, i made my own loop so i could remove 1 from the variable “flashlightBatteryFuel”, and i get this error :
Assets/Scripts/Remove_Battery.js(30,9): BCE0070: Definition of 'Remove_Battery.FuelSystem()' depends on 'Remove_Battery.FuelSystem()' whose type could not be resolved because of a cycle. Explicitly declare the type of either one to break the cycle.
Two of them to be exact, on the same line. And heres my full code(s) :
Script file name : Remove_Battery (i think this ones causing the problem since it has the loop)
#pragma strict
public static var flashlightBatteryFuel : int;
public static var outOfFuel : boolean;
public static var removeBatteryPack : boolean;
function Start () {
flashlightBatteryFuel = 100;
outOfFuel = false;
removeBatteryPack = false;
FuelSystem();
}
function Update () {
if(removeBatteryPack == true){
Destroy(gameObject);
}
}
function FuelSystem(){
yield WaitForSeconds(20);
if(Flashlight.flashOn == true){
flashlightBatteryFuel -=1;
}
print(flashlightBatteryFuel);
if(flashlightBatteryFuel <= 0){
outOfFuel = true;
}
FuelSystem();
}
Script file name : Battery
#pragma strict
var collideObject : GameObject;
function Start () {
}
function Update () {
}
function OnTriggerEnter(other : Collider){
if(other.tag == "Battery"){
Remove_Battery.removeBatteryPack = true;
Remove_Battery.flashlightBatteryFuel = 100;
if(Remove_Battery.outOfFuel == true){
Remove_Battery.outOfFuel = false;
}
}
}
Script file name : Flashlight
#pragma strict
public var Spotlight : GameObject;
private var myLight : Light;
public var flashlightSound : AudioClip;
var audiofile : AudioSource;
var audioPlayable : boolean;
public static var flashOn : int;
function Start()
{
myLight = Spotlight.GetComponent(Light);
audioPlayable = true;
flashOn = 0;
}
function Update()
{
if (Input.GetKeyDown("f"))
{
FlashSetting();
}
}
function FlashSetting(){
if(audioPlayable == true){
if(flashOn == 0){
flashOn +=1;
light.intensity =2;
audiofile.PlayOneShot(flashlightSound);
audioPlayable = false;
yield WaitForSeconds(1);
audioPlayable = true;
}
if(Input.GetKeyDown("f")){
if(flashOn == 1){
if(Remove_Battery.outOfFuel == false){
flashOn = 0;
light.intensity =0;
audiofile.PlayOneShot(flashlightSound);
audioPlayable = false;
yield WaitForSeconds(1);
audioPlayable = true;
if(Remove_Battery.outOfFuel == true){
print("Out of Batteries");
}
}
}
}
}
}
Anyone knows what im doing wrong? I really want that loop there, is there any way i could replace it without getting this error?