void OnCollisionStay(Collision col) //in case { if (col.gameObject.name.EndsWith("Spongebob")) { SpongeBob spongeBob = col.gameObject.GetComponent <SpongeBob>(); if (!spongeBob.invincible) { spongeBob.health -= damage; onDamage.Invoke(); health = 0; } } }
void OnCollisionEnter(Collision col) { if (col.gameObject.layer == 10 && !benefitOfTheDoubt) //wall layer { benefitOfTheDoubt = true; direction = !direction; StartCoroutine(WaitForIt()); } else if (col.gameObject.name.EndsWith("Spongebob")) { SpongeBob spongeBob = col.gameObject.GetComponent <SpongeBob>(); if (!spongeBob.invincible) { spongeBob.health -= damage; onDamage.Invoke(); health = 0; } } }