Question by
DrLlamastein · Nov 25, 2017 at 05:06 PM ·
gameobjectcollidertriggeroncollisionenter
When a collider enters a trigger
MY enemies already have a trigger on them and so does my player. I found out that a trigger cannot trigger another trigger so I added another game object to my enemies that has a collider. But in my player where I have OnCollisionEnter2D nothing happens.
https://gyazo.com/81d1a5abe31089fd33f194cb6120c91f
private void OnCollisionEnter2D(Collision2D col) {
health -= Mathf.RoundToInt(Random.Range(5, 15));
uiM.UpdateHealth(health);
GameObject explosion = Instantiate(explosionPrefab, transform.position, Quaternion.identity) as GameObject;
Destroy(explosion, 0.5f);
CameraShake.instance.Shake(0.05f, 0.1f);
Destroy(col.gameObject);
if (health <= 0) {
Die();
}
}
Comment
Answer by shakecaine · Nov 26, 2017 at 11:36 AM
Use OnTriggerEnter2D if you work with triggers.
You also have to remember that if you attach another object to your orginal one then you need to reference the parent(original object) of the object. Not the attached object itself.