Small combo code.

Hello. I just need some help figuring out why won’t unity detect that when the left button is pressed the bools that are in the if parameters have to change to “true” from “false”. I leave the code here. I’d be glad if someone helped me on this one.
NOTE: IBA stands for: in between attacks.
NA stands for: Next attack.
using UnityEngine;
using System.Collections;

public class MeeleAttack : MonoBehaviour {

		public bool attack1 =false;
		public bool attack2 = false;
		public bool attack3 = false;
		float IBA = 1.0f;
		float NA = 0.0f;
		bool Combo1 =false;
		// Use this for initialization
		void Awake (){
		}
		void Start () {
		}
		
		// Update is called once per frame
		void Update () {
			if (Input.GetMouseButtonDown (1)){
				attack1 =true;
				NA = Time.time + IBA;
			Debug.Log("Pressed left click.");
			

			}
			if(Input.GetMouseButtonDown(1)&& Time.time <= NA){
				attack2 =true;
				NA = Time.time + IBA;
				Combo1 = true;
			Debug.Log("Pressed left click.");
			
		}
			if(Input.GetMouseButtonDown(1)&& Time.time <= NA&& Combo1 == true){
			attack3 = true;
			Debug.Log("Pressed left click.");
		}
		}
		
	}

I added the debug.log marks to check if the button was detected. Thing is that i get 3 debug logs at the same time, which means that the three ifs are acting at the same time, should i go for a switch case method? Thanks for all the help.

This code: Input.GetMouseButtonDown(1) ...detects the right mouse button, not the left. The left is button 0.

Sorry about that, still i want the right button to be detected, so 1 was intended, but i confused the print line by putting left on it.

There is absolutely no reason to use obscure variable names and provide a key. The names will all be compiled away in the final product. If you mean inBetweenAttacks write inBetweenAttacks. None of this IBA nonsense

Yeah, it was for my own comodity. But that is completely true. Thats why i specified what each "obscure variable name" meant. They can and i will most likely change it as soon as the script works as intended or before.

1 Answer

1

If you do want the player to push the buttton three times to trigger the combo, just invert the order of the ifs:

public class MeeleAttack : MonoBehaviour
{

    public bool attack1 = false;
    public bool attack2 = false;
    public bool attack3 = false;
    float IBA = 1.0f;
    float NA = 0.0f;
    bool Combo1 = false;

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(1) && Time.time <= NA && Combo1 == true)
        {
            attack3 = true;
            Debug.Log("Triggered attack 3");
        }

        if (Input.GetMouseButtonDown(1) && Time.time <= NA)
        {
            attack2 = true;
            NA = Time.time + IBA;
            Combo1 = true;
            Debug.Log("Triggered attack 2");

        }

        if (Input.GetMouseButtonDown(1))
        {
            attack1 = true;
            NA = Time.time + IBA;
            Debug.Log("Pressed left click.");
        }
    }

}

If you want the combo to be triggered automatically without releasing the button: You are using Input.GetButtonDown() which only trigger at the exact instant the button is pressed. If you want it to trigger whenever the button is mantained use Input.GetButton().

Please create a new question for the animation part as it is a completely different matter. Have you checked that the Debugs are shown without the animation code?

I will create a new question. but for now i just want to fix the issue with the third instance of the combo not triggering at all. The debugs are not shown without the animation. Thanks

It works for me without the animations. Three clicks within 1 or 2 seconds trigger the three attacks.

Maybe the animations are indeed the problem. Ill open another question and try to get them fixed! thanks dmg0600!