//------------------------------------------------------------------------------------------------------------------ /* * METODO QUE SE EJECUTARÁ AL PRODUCIRSE UNA COLISION CON UN COLLIDER ONTRIGGER */ void OnTriggerEnter2D(Collider2D collision) { //////////////////////// MUNICION ////////////////////////// if (collision.gameObject.tag == "municion") { GameObject cajaMunicion = collision.gameObject; //Obtener referencia si no se ha obtenido if (generadorMunicion == null) { generadorMunicion = GameObject.Find("ControladorJuego").gameObject.GetComponent <GestionMunicion>(); } //Desactivar los collider de la caja generadorMunicion.desactivarCaja(cajaMunicion.GetComponent <Municion>().name); //Si la caja no esta abierta if (!cajaMunicion.GetComponent <Municion>().isAbierta()) { //Aumentar las balas estadoJugador.aumentarBalas(cajaMunicion.GetComponent <Municion>().obtenerPropiedades()); //Marcar como abierta cajaMunicion.GetComponent <Municion>().abrirCaja(); } } }
//------------------------------------------------------------------------------------------------------------------ /* * METODO QUE SE EJECUTA AL INICIAR EL SCRIPT */ void Start() { generadorMunicion = GameObject.Find("ControladorJuego").gameObject.GetComponent <GestionMunicion>(); gestorInterfaz = GameObject.Find("ControladorJuego").gameObject.GetComponent <GestionInterfaz>(); gestionPlantas = GameObject.Find("ControladorJuego").gameObject.GetComponent <GestionPlantas>(); }