public class DamageController : MonoBehaviour

{

public LayerMask targetLayer;

public UnitController mainUnit;

public int damage = 2;

public bool damageTriggerOn;

public bool dealTime;


private void OnTriggerStay(Collider other)

{

if (damageTriggerOn)

{

Debug.Log(other.gameObject.name + " 1");


if (((1 << other.gameObject.layer) & targetLayer) != 0)

{

Debug.Log(other.gameObject.name + " 2");

if (other.TryGetComponent(out UnitController targetUnit))

{

damageTriggerOn = false;

Debug.Log(other.gameObject.name + " 3");

targetUnit.ReceiveAnAttack(damage, mainUnit);

}

}

}

}


public IEnumerator DamageTriggerOn(float dealTime)

{

damageTriggerOn = true;

yield return new WaitForSeconds(dealTime);

damageTriggerOn = false;

yield return null;

}

}

enter로 했더니 이미 범위 안에 있는애들은 딜 안받아서 패스

Stay로 했더니 여러번 딜이 들어와서 타격시 bool로했더니 여러마리가 동시에 공격당했을때 최초의 한놈만 딜받아서 패스

지금 생각하는건 딕션너리를 만들어서 유닛을 키로 넣고 값을 bool로 넣어서 스테이에다가 foreach로 사전돌면서 bool값이 false인놈만 딜주고 true로 바꿀생각인데

스테이에다가 이러면 뭔가 효율성에서 거지같은 느낌이 드네요 .. 

무슨 좋은방법 없을까요