So i have my scripts below and what is supposed to happen is a timer counts down them spawns a beam then restarted the counter and then if the beam is still spawned just restart the counter without spawning a beam then once the beam is collected by the player the value is checked and the beam is supposed to be able to be spawned again but for some reason when it comes to that the value is changing when it is called but after that goes back to normal so whats happening here ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BlueTracker : MonoBehaviour {
public GameObject Beam;
public float BlueTimer;
float Due;
public int isBeamSpawn;
// Use this for initialization
void Start () {
Due = Random.Range (10, 15);
BlueTimer = Due;
}
// Update is called once per frame
void Update () {
BlueTimer -= Time.deltaTime;
if (BlueTimer <= 0 && isBeamSpawn == 0) {
Instantiate (Beam, transform.position, transform.rotation);
Due = Random.Range (10, 15);
BlueTimer = Due;
isBeamSpawn = 1;
} else if (BlueTimer <= 0 && isBeamSpawn == 1) {
Due = Random.Range (10, 15);
BlueTimer = Due;
}
}
public void BeamCheck(int spawned)
{
isBeamSpawn -= spawned;
}
}
my other script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Collect : MonoBehaviour {
public GameObject Sign;
public BlueTracker blue;
// Use this for initialization
void Awake () {
blue = Sign.GetComponent<BlueTracker> ();
}
// Update is called once per frame
void Update () {
}
void OnTriggerStay(Collider other)
{
if (Input.GetKeyDown (KeyCode.E)) {
blue.BeamCheck(1);
Destroy (gameObject);
}
}
}