hi, I’m using C#
I have situation like this:
player can shoot bullets each player has stats that it can upgrade like (bullet range, bullet speed, bullet dmg, RELOAD TIME)
problem is in reload time;
float reload (current reload time)
float maxreload (number that “reload” should be to enable shooting)
when bullet is triggered, reload time drops on 0, if (reload < maxreload) then I want to make reloading increasing for 1 EACH SECOND
You have to increment reload with Time.deltaTime because this is the time that has elapsed since the last update() cycle. By adding this to your reload variable, it will hold the total time that has passed since the last shot.
However …
it is probably not working at your side because you are comparing it with maxreload and the chance that reload will be exactly the same is very small indeed!
so try to compare it like … reload >= maxreload, and it will give you joy!
Better to use coroutines for this sort of thing anyway (but don’t try to mix them with Update; rokstar234’s code won’t work because it will start a new coroutine every frame):
public GameObject bullet;
public float reloadTime = 3;
IEnumerator Start() {
while (true)
{
if (Input.GetMouseButtonDown(0))
{
Network.Instantiate(bullet, transform.position, transform.rotation, 0);
yield return new WaitForSeconds(reloadTime);
}
yield return null;
}
}