Hello.
First of all I hope thats proper place to post this thread. I was thinking about puttng it at “Physics”…
I would like to add Colliders that are hit during OnTrigerStay to array, to check which ones were damaged already during current weapon swing, to avoid damaging one enemy multiple times.
For ease I decieded to take thier names and store strings in array.
Alternatively I can use list, but I reckon array would be more efficient, since it is attack function, so it will be used quite often. Anyway i tired both options, but with no success.
Thats how relevant code look like, but only OnTrigerStay is important as far as I am concerned.
[SerializeField] protected float m_StartCollisionDelay;
[SerializeField] protected float m_StopCollisionDelay;
[SerializeField] protected LayerMask m_Mask;
protected Collider m_Collider;
protected bool m_ActiveAttackTrigger;
public string[] m_SwingedEnemies;
public int i = 0;
protected IEnumerator SwingIE()
{
yield return new WaitForSeconds(m_StartCollisionDelay);
m_ActiveAttackTrigger = true;
yield return new WaitForSeconds(m_StopCollisionDelay);
m_ActiveAttackTrigger = false;
i = 0;
m_SwingedEnemies = null;
}
private void OnTriggerStay(Collider other)
{
if (!m_ActiveAttackTrigger) { return; }
if (m_SwingedEnemies.Contains(other.gameObject.name)){ return; }
else
{
m_SwingedEnemies[i] = other.gameObject.name;
Debug.Log(m_SwingedEnemies[i]);
i += 1;
}
if (other.gameObject == m_Character.gameObject) { return; }
if (m_Character is EnemyCharacter)
{
if (other.GetComponent<EnemyCharacter>() != null) return;
}
var damageable = other.GetComponent<IDamageable>();
if (damageable == null) { return; }
Damage(damageable);
}
My console errors after performing swing at enemy.
Those errors are showing up at line 27 of provided code. My only guess is that there are too many colliders at one momen, but I can be wrong ofcourse.
How can i solve this issue? Am I doing something wrong?
