private void OnTriggerEnter(Collider other) { if (!agente.isOnOffMeshLink) { // Si encuentras un enemigo y no está en la lista de enemigos if (other.tag == "Enemigo") { EnemigoGenerico aux = other.GetComponent <EnemigoGenerico>(); // Actualizas al enemigo de que hay hormiga cerca if (!aux.hormigasCerca.Contains(this)) { aux.hormigasCerca.Add(this); } // Actualizas a la hormiga y avisas a la reina de este enemigo if (!enemigosCerca.Contains(aux)) { if (aux.hormigasAtacandole.Count < 2) { if (aux.hormigasAtacandole.Count == 0) { reina.RecibirAlertaEnemigo(aux); } else if (aux.hormigasAtacandole[0] == this) { reina.RecibirAlertaEnemigo(aux); } } enemigosCerca.Add(aux); } } else if (other.tag == "Trigo") { Comida aux = other.gameObject.GetComponent <Comida>(); if (!aux.hormigasCerca.Contains(this)) { aux.hormigasCerca.Add(this); } if (!aux.haSidoCogida && !aux.laEstanLLevando && aux.hormigaQueLlevaLaComida == null) { reina.RecibirAlertaComida(aux); } } else if (other.tag == "Huevo") { Huevo aux = other.GetComponent <Huevo>(); // Actualizas al huevo de las hormigas que tiene cerca if (!aux.hormigasCerca.Contains(this)) { aux.hormigasCerca.Add(this); } // Actualizas la lista de huevos cerca if (!huevosCerca.Contains(aux)) { huevosCerca.Add(aux); } } } }
public void Setup() { pajarosComunes = new PajarosComunes(10); red = new Red(10); bomb = new Bomb(10); chuck = new Chuck(95, 10); terence = new Terence(10); matilda = new Matilda(10); pajaros = new List <Pajaros> { pajarosComunes, red, bomb, chuck, terence, matilda }; huevo = new Huevo(1000); paredDeVidrio = new ParedVidrio(20); obreros = new CerditosObreros(); paredDeMadera = new ParedMadera(20); obstaculos = new List <Obstaculo> { paredDeVidrio, obreros, paredDeMadera }; islaPajaros = new IslaPajaros(pajaros, obstaculos); }
private void OnTriggerExit(Collider other) { // Si un enemigo sale de nuestro collider, y estabamos luchando con el actualizar la lista if (other.tag == "Enemigo") { EnemigoGenerico aux = other.GetComponent <EnemigoGenerico>(); aux.hormigasCerca.Remove(this); enemigosCerca.Remove(aux); } else if (other.tag == "Trigo") { Comida aux = other.gameObject.GetComponent <Comida>(); aux.hormigasCerca.Remove(this); } else if (other.tag == "Huevo") { Huevo aux = other.GetComponent <Huevo>(); huevosCerca.Remove(aux); aux.hormigasCerca.Remove(this); } }