Hallo dear community.
I have a value that increases with 2 different type of shots (small/big) filling my overheat.
The code ads those values and decreases them just as they are supposed.
However because I use Time.time (same problem with Time.deltaTime) the subtracted intervals are not even.
This is important because see awesome art work =P.
How can I fix this problem or what method could I use else to achieve the subtract 1 every second.
This is how far I got myself:
using UnityEngine;
using System.Collections;
public class FirePlayerCanon : MonoBehaviour
{
public GameObject smallLaser;
public GameObject bigLaser;
public float smallShot = 2.1f;
public float bigShot = 4f;
public float overheat;
public bool heating =false;
public float subtractionDelay = 1f;
public float timeTillNextSubtraction;
private float minOverheat = 0f;
private float maxOverheat = 7f;
// Update is called once per frame
void Update ()
{
//fire normal with out delay.
var wasAltHit = Input.GetKeyDown(KeyCode.LeftAlt);
var wasCtrlHit = Input.GetKeyDown(KeyCode.LeftControl);
// instatiate smallShot.
if (wasCtrlHit && heating == true)
{
Instantiate(smallLaser,transform.position,Quaternion.identity);
//add smallShot valeu to overheat.
overheat = overheat += smallShot;
}
// instatiate bigShot.
if (wasAltHit && heating == true)
{
Instantiate (bigLaser, transform.position, Quaternion.identity);
//add smallShot valeu to overheat.
overheat = overheat += bigShot;
}
//Set max overheated value witch shall not be passed
if (overheat >= maxOverheat)
{
overheat = maxOverheat;
heating = false;
}
//Set min overheated value witch shall not be passed
if (overheat <= minOverheat)
{
overheat = minOverheat;
heating = true;
}
if (Time.time > timeTillNextSubtraction)
{
overheat = overheat -= 1f;
timeTillNextSubtraction = Time.time + subtractionDelay;
}
}
}
I am an absolute beginner in terms of coding and would appreciate an answer with an example on how to use. Unity Documentation is not always a 100% clear to me in terms of usage in combination with other code.
Any help at all is much appreciated.
Regards
Chris