I’m working on a simple Multi-Kill script for my game.
_
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KillManager : MonoBehaviour
{
[Header("Player Statistics")]
public float kills;
public float prevKills;
public float deaths;
[Header("Multi-Kill Timer")]
public float speed;
public float killTimer;
public float killtimerReset;
public bool killChain;
public float chainKills;
[Header("Multi-Kill Status")]
public bool doubleKill;
public bool tripleKill;
public bool quadKill;
public bool pentaKill;
// Start is called before the first frame update
void Start()
{
prevKills = 0;
}
void multiTimer()
{
if(kills > prevKills)
{
killChain = true;
if (killChain)
{
killTimer -= speed * Time.deltaTime;
}
if(killTimer <= 0)
{
killChain = false;
prevKills = kills;
}
if(chainKills == 2)
{
doubleKill = true;
}
if (chainKills == 3)
{
tripleKill = true;
}
if (chainKills == 4)
{
quadKill = true;
}
if (chainKills == 5)
{
pentaKill = true;
}
}
}
// Update is called once per frame
void Update()
{
multiTimer();
chainKills = kills - prevKills;
if (doubleKill)
{
tripleKill = false;
quadKill = false;
pentaKill = false;
}
if (tripleKill)
{
doubleKill = false;
quadKill = false;
pentaKill = false;
}
if (quadKill)
{
doubleKill = false;
tripleKill = false;
pentaKill = false;
}
if (pentaKill)
{
doubleKill = false;
tripleKill = false;
quadKill = false;
}
}
}
_
How can I make it so I can reset the timer back to it’s default timer 5f without stopping the counting down?
I tried this:
_
if(chainKills == 2)
{
doubleKill = true;
killTimer = 5;
killTimer -= speed * Time.deltaTime;
}
_
However that simply hard-codes killTimer to 5 and will not count down like I’d like it. Please share your unity expertise with a aspiring novice!
While visiting the toilet I believe I found the answer to my question.
public float killTimer;
public float maxTimer;
public float diffrenceTimer;
diffrenceTimer = maxTimer(5) - killTimer(whatever it is)
killTimer = killTimer + diffrenceTimer;
well thats a really overenginered solution and a bit hard to understand. setting the value to 5 will never stop the countdown, so what is stopping the countdown is something else. first you need to remove the killchain = true inside the multplier method since thats a bug 100%, whats the kills value? it is set in the inspector? is there any extra code you are not sharing? since if kills and prevkills are not being updated and the killchain is always true is not posible that just after setting killtimer = 5; the countdown stops.