Help on my combo system

Hello, i trying to do a combo system like DmC or a hack n slash game but i need help to improve.
i want to press 3 times punch1(Z) and push 2 times Z and 1 time X to do another atack.
basically I ask help to improve the system or create a better.

using UnityEngine;
using System.Collections;

public class ComboSystem : MonoBehaviour {
    private int point = 1;
    private int point2 = 1;
    private int totalCombo = 4;
    private float timer = 0;
    private float timer2 = 0;
    public Animator anim;
    void Start () {

    }
    void Update () {
        Puntos ();
        tiempoentrecombos ();
        combo ();
        print (point2);
   
    }
    void Puntos(){
        //anim.SetBool ("Atacando", false);
        //if (point <= totalCombo) {
            if (Input.GetKeyDown (KeyCode.Z)) {
                //anim.SetBool ("Atacando", true);
                timer = 1;
                point += 1;
            }
        if (Input.GetKeyDown (KeyCode.C)) {
            timer2 = 1;
            point2 += 1;
        }
        //} else {
            //point = 1;
            /*anim.SetBool ("hit1", false);
            anim.SetBool ("hit2", false);
            anim.SetBool ("hit3", false);
            anim.SetBool ("hit4", false);*/
        //}
    }
    void tiempoentrecombos(){
        if (timer > 0) {
            timer -= Time.deltaTime;
        }
        if (timer2 > 0) {
            timer2 -= Time.deltaTime;
        }
        if (timer <= 0) {
            point = 1;
        }
        if (timer2 <= 0) {
            point2 = 1;
        }
        if(point == 1 || point2 == 1){
            anim.SetBool ("hit1", false);
            anim.SetBool ("hit2", false);
            anim.SetBool ("hit3", false);
            anim.SetBool ("hit4", false);
            anim.SetBool ("hit5", false);
        }
    }
    void combo(){
        if (point == 1) {
            //print ("1");
        }
        if (point == 2 && !anim.GetCurrentAnimatorStateInfo(0).IsName("Espada")) {
            //print ("2");
            anim.SetBool ("hit1", true);
        }
        if (point == 3) {
            //print ("3");
            anim.SetBool ("hit2", true);
        }
        if (point == 4) {
            anim.SetBool ("hit3", true);
        }
        if (point == 3 && point2 == 2) {
            anim.SetBool ("hit4", true);
        }
        if (point2 == 3) {
            anim.SetBool ("hit5", true);
        }
    }
}

PD: is a good choice do with arrays?

1 Like

Using code tags properly - Unity Engine - Unity Discussions Could you do this first? Its hard to read.

Welcome too, I see its you first post! :slight_smile:

This code seems pretty good. Try using anim.Play() instead of setting the bools.

You could also take this out:

if(point == 1 || point2 == 1){
            anim.SetBool ("hit1", false);
            anim.SetBool ("hit2", false);
            anim.SetBool ("hit3", false);
            anim.SetBool ("hit4", false);
            anim.SetBool ("hit5", false);
        }

@Felhip3 There is a similar thread here:

Though your combo is more complex than the OP of that thread.
Similarly, but with some improvements, this how I would define your combo using Panda BT:

tree("Combo")
    sequence
        WaitButton("Z")
        DoHit 1
        WaitButton("Z", 1.0) // This means wait for the button "Z" with a timeout of 1 second.
        DoHit 2
        WaitButton("Z", 1.0)
        DoHit 3
        WaitButton("Z", 1.0)
        WaitButton("Z", 1.0)
        WaitButton("X", 1.0)
        DoHit 4

This script might look a bit exotic, but it is functional. I just would to demonstrating how simple and straight forward it would be to define a combo using this tool. If you find this simplicity appealing, I could explain to you how to setup your combo system if you want to explore this solution further.