// hurt all the specimen of the specie by a given amount public void HurtSpecimens() { FreakOut(); foreach (GameObject specimenObject in agents) { Specimen specimen = specimenObject.GetComponent <Specimen>(); specimen.TakeDamage(HurtDamage); } }
//Detect collisions between the GameObjects with other collider void OnTriggerEnter2D(Collider2D other) { //Check for a match with the specified name on any GameObject that collides with your GameObject if (other.gameObject.CompareTag(SpecieToEat)) { Specimen otherSpecimen = other.gameObject.GetComponent <Specimen>(); otherSpecimen.TakeDamage(attackStrength); GetComponent <Specimen>().Eat(otherSpecimen); } }