::For both garlic and knife, I’m unable to damage the enemy. For the garlic script, there is a null reference on if(collision.CompareTag("Enemy") && !markedEnemies.Contains(collision.gameObject))
When I debugged projectileWeaponBehavior script, the only things that are getting triggered are player and collector. I think it is not supposed to get the collector as a collision in OnTriggerEnter2D since both the projectile and collector have 2d collider with isTrigger on. OnTriggerEnter2D part of projectileWeaponBehavior script:
protected virtual void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Enemy"))
{
EnemyStats enemy = collision.GetComponent<EnemyStats>();
enemy.TakeDamage(currentDamage);
ReducePierce();
}
else if (collision.CompareTag("Prop"))
{
if(collision.gameObject.TryGetComponent(out BreakableProps breakable))
{
breakable.TakeDamge(currentDamage);
ReducePierce();
}
}
}
OnTriggerEnter2D part in garlic script that is getting null reference:
protected override void OnTriggerEnter2D(Collider2D collision)
{
if(collision.CompareTag("Enemy") && !markedEnemies.Contains(collision.gameObject))
{
EnemyStats enemy = collision.GetComponent<EnemyStats>();
enemy.TakeDamage(currentDamage);
markedEnemies.Add(collision.gameObject);
}
else if (collision.CompareTag("Prop"))
{
if (collision.gameObject.TryGetComponent(out BreakableProps breakable) && !markedEnemies.Contains(collision.gameObject))
{
breakable.TakeDamge(currentDamage);
markedEnemies.Add(collision.gameObject);
}
}
}