Hi,
I’m trying to have a heat system for machine guns in my game. It’s simple, when you shoot, you produce heat and it doesn’t get cooling. When you don’t shoot, the cooling occurs. My problem is that when I first shoot, the cooling stop but doesn’t happen again. Ever.
Here is my code:
using UnityEngine;
using System.Collections;
public class GameController : MonoBehaviour {
public float energy, heat, energyGenerated, heatRedux;
public float energyUsed, heatProduced;
public bool IsShootingMG;
void Start(){
StartCoroutine (HeatFunction ());
StartCoroutine (EnergyFunction ());
}
IEnumerator EnergyFunction(){
while(true)
{
yield return new WaitForSeconds(oneSecond);
energy = energy + energyGenerated;
}
}
IEnumerator HeatFunction(){
while(IsShootingMG == false){
yield return new WaitForSeconds(oneSecond);
if(heat > 0){
heat = heat - heatRedux;
if(heat < 0){
heat = 0;
}
}
}
}