Hello guys,
I have trying to resolve this problem for a very long time and I seriously can’t figure out what to do to fix this. I have the below code on a object with a Box Collider 2D set to Trigger:
public Object CollectableDestroyedEffect;
public Object BallDiesEffect;
public Object EnemyDestroyedEffect;
private string objectTag;
void OnTriggerEnter2D(Collider2D other)
{
objectTag = other.gameObject.tag;
switch (objectTag)
{
case "Enemy":
other.GetComponent<EnemyCollisions>().DestroyEnemy(true, false);
break;
case "Collectable":
Instantiate(CollectableDestroyedEffect, other.transform.position, Quaternion.identity);
Destroy(other);
break;
case "Ball":
//Destroy(other);
Instantiate(BallDiesEffect, other.transform.position, Quaternion.identity);
GameManager.instance.SpawnBall();
break;
case "Projectile":
Instantiate(EnemyDestroyedEffect, other.transform.position, Quaternion.identity);
Destroy(other);
break;
//default:
// Instantiate(CollectableDestroyedEffect, other.transform.position, Quaternion.identity);
// Destroy(other);
// break;
}
}
What I am having problem with is the tag “Collectable”.
I made sure the tag is correct, I made sure all of the objects have a RigidBody2D, and I made sure that they are on the same plane and same layer.
The weird thing is that the effects are instantiated correctly (so the Instantiate code) runs and I can see, thing is, the objects are getting destroyed at all.
Worthy of note is that the Collectable tagged objects have Box Collider 2D and set to trigger.
Any idea how I can fix this?