void Attack()
{
try
{
if (direction.y == 1)
{
AttackAnimation(upTrigger);
}
else if (direction.y == -1)
{
AttackAnimation(downTrigger);
}
else if (direction.x == 1)
{
AttackAnimation(rightTrigger);
}
else if (direction.x == -1)
{
AttackAnimation(leftTrigger);
}
else
{
Debug.LogError("Error Imposible direction. line 65. diretion X = " + direction.x + "diretion Y = " + direction.y);
}
}
catch (System.Exception e) {
}
}
void AttackAnimation(GameObject direction)
{
StartCoroutine(start());
IEnumerator start()
{
direction.GetComponent<BoxCollider2D>().enabled = true;
yield return new WaitForSeconds(0.04f);
direction.GetComponent<BoxCollider2D>().enabled = false;
Debug.Log("Attacking");
}
}
,
[Header("Attack Triggers")]
public GameObject upTrigger;
public GameObject downTrigger;
public GameObject leftTrigger;
public GameObject rightTrigger;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate()
{
if(Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.Joystick1Button2)){ Attack(); }
}
void Attack()
{
try
{
if (direction.y == 1)
{
AttackAnimation(upTrigger);
}
else if (direction.y == -1)
{
AttackAnimation(downTrigger);
}
else if (direction.x == 1)
{
AttackAnimation(rightTrigger);
}
else if (direction.x == -1)
{
AttackAnimation(leftTrigger);
}
else
{
Debug.LogError("Error Imposible direction. line 65. diretion X = " + direction.x + "diretion Y = " + direction.y);
}
}
catch (System.Exception e) {
}
}
void AttackAnimation(GameObject direction)
{
StartCoroutine(start());
IEnumerator start()
{
direction.GetComponent<BoxCollider2D>().enabled = true;
yield return new WaitForSeconds(0.04f);
direction.GetComponent<BoxCollider2D>().enabled = false;
Debug.Log("Attacking");
}
}
}