Question by
Dynaheart · Jan 30, 2020 at 02:40 PM ·
countingfightingame
Any way I can reset this counter to 0?
Ok, so I've made this code on my own, I only started with Unity a month ago so there are probably a lot of different solutions, but I couldn't manage to find any. Here's the code
public class PlayerCombat : MonoBehaviour
{
public Animator animator;
public LayerMask enemyLayers;
public Transform attackPoint;
public float attackRange = 0.5f;
public int attackDamage = 34;
public float attackRate = 2f;
float nextAttackTime = 0f;
int comboCount = 0;
public float comboRate = 1.5f;
float nextComboTime = 0f;
// Update is called once per frame
void Update ()
{
if (Time.time >= nextAttackTime)
{
if (Input.GetKeyDown(KeyCode.C))
{
if (comboCount == 0)
{
nextAttackTime = Time.time + 1f / attackRate;
if (Time.time >= nextComboTime)
{
nextComboTime = Time.time + 1f / comboRate;
comboCount = 1;
Attack1();
}
}
if (comboCount == 1)
{
nextAttackTime = Time.time + 1f / attackRate;
if (Time.time >= nextComboTime)
{
nextComboTime = Time.time + 1f / comboRate;
comboCount = 2;
Attack2();
}
}
if (comboCount == 2)
{
nextAttackTime = Time.time + 1f / attackRate;
if (Time.time >= nextComboTime)
{
nextComboTime = Time.time + 1f / comboRate;
comboCount = 3;
Attack3();
}
}
}
}
//
}
The code works well, "Attack()" voids are just for animation and hitboxes, but this part is what manages de Combo number (three attacks) and now I just need to reset the counter, if you could help this newbie I'd really appreciate it, thanks in advance.
Comment