OnTriggerEnter only works on one collision?
I have an OnTriggerEnter function with two objects set to detect collision.
Both have a tagged hitbox and attackbox, both with colliders set to trigger, and only the Player seems to be detecting collisions. I have tried setting kinematic rigidbodies on either, and both. Both are on the default layer, with collision set on it.
I really don't see what the problem could be. Again, I AM getting the "Enemy Takes Damage", so the function is obviously working, just not for both.
public bool knockDownAttack;
public float attackStrength;
public GameObject otherObject;
void OnTriggerEnter (Collider other)
{
if (gameObject.tag == "PlayerAttackBox" && other.tag == "EnemyHitBox")
{
EnemyTakeDamage();
}
else if (gameObject.tag == "EnemyAttackBox" && other.tag == "PlayerHitBox")
{
PlayerTakeDamage();
}
else
{
return;
}
}
void EnemyTakeDamage()
{
Debug.Log("Enemy takes damage");
}
void PlayerTakeDamage()
{
Debug.Log("Player takes damage");
}
Did this ever get resolved? I have a similar issue where I am trying to instantiate a particle effect on collision on two different objects, but only one works at a time.
void OnTriggerEnter2D(Collider2D other){
if (other.tag == "Wall") {
Instantiate (CannonSplosion, other.transform.position, other.transform.rotation);
Destroy (this.gameObject);
}
if (other.tag == "Player") {
Instantiate (CannonSplosion, other.transform.position, other.transform.rotation);
Destroy (this.gameObject);
}
}
It only seems to instantiate the particle effect when it hits the player, but not the wall/ground of my tilemap.