Код: Выделить всё
using System Collections;
using System.Collections.Generic;
using UnityEngine;
public class AoESelfDetonate : MonoBehaviour
{
public bool CanAoE = true;
public bool isAoE = false;
public float AoECoolDown = 5f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(2))
{
Debug.Log("Button Down");
StartCoroutine(CooldownNoHit());
if (CanAoE == true)
{
Debug.Log("Can AoE");
CanAoE = false;
isAoE = true;
Animator anim = GetComponent();
anim.SetTrigger("Explode");
StartCoroutine(ResetAttackCooldown());
}
}
}
void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log("On Hit");
if (collision.gameObject.CompareTag("Enemy") && isAoE == true)
{
Destroy(collision.gameObject);
Debug.Log("On Destroy");
}
}
IEnumerator ResetAttackCooldown()
{
yield return new WaitForSeconds(AoECoolDown);
CanAoE = true;
}
IEnumerator CooldownNoHit()
{
isAoE = true;
yield return new WaitForSeconds(0.60f);
isAoE = false;
}
}
Редактировать: Хитбокс тоже не работает
Подробнее здесь: https://stackoverflow.com/questions/789 ... -loops-but