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.
– robertbuSorry 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.
– komo97There 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
– KiwasiYeah, 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.
– komo97