Пример #1
0
    //7.COLISIONES CONSTANTES CON TRIGGERS
    void OnTriggerStay2D(Collider2D other)
    {
        //Cofre
        Cofre compCofre = other.GetComponent <Cofre>();
        MovimientoCocodrilo compCoco = other.GetComponent <MovimientoCocodrilo>();

        if (compCofre != null && tiempo > tiempoDeInmunidad && compCofre.enemigo && compCofre.abierto)
        {
            RecibeDaño(2, other.gameObject);
        }
        //Cocodrilos
        else if (compCoco != null && tiempo > tiempoDeInmunidad)
        {
            RecibeDaño(1, other.gameObject);
        }
        //Pinchos
        else
        {
            ColisionPichos(other.gameObject);
        }
    }
Пример #2
0
    //6.COLISIONES CON TRIGGERS
    void OnTriggerEnter2D(Collider2D other)
    {
        Disparo             compBala   = other.GetComponent <Disparo>();
        Moneda              compMoneda = other.GetComponent <Moneda> ();
        MovimientoCocodrilo compCoco   = other.GetComponent <MovimientoCocodrilo> ();
        Cofre compCofre = other.GetComponent <Cofre> ();

        //Colisión con bala enemiga
        if (compBala != null && compBala.TipoDeBala == Disparo.TipoBala.BalaEnemigo)
        {
            Destroy(other.gameObject);
            if (tiempo > tiempoDeInmunidad)
            {
                RecibeDaño(2, other.gameObject);
            }
        }


        //Colisión con pociones
        else if (other.gameObject.tag == "Poción")
        {
            GetComponent <AudioSource>().PlayOneShot(cogepocion);
            GameManager.instance.GanaPoción();
            Destroy(other.gameObject);
        }
        else if (other.gameObject.tag == "Finish")
        {
            GameManager.instance.FinNivel();
        }
        else if (other.gameObject.tag == "Checkpoint")
        {
            if (GameManager.instance.NivelActual() != 3)
            {
                GameManager.instance.Checkpoint();
            }
            else
            {
                GameManager.instance.FijaCamara();
                Destroy(other.gameObject);
            }
        }
        else if (other.gameObject.tag == "DeadZone")
        {
            GameManager.instance.RecibeDaño(10, true);
        }


        //Colisión con monedas
        else if (compMoneda != null)
        {
            GameManager.instance.GanaMonedas(compMoneda.Valor);
            Destroy(other.gameObject);
        }

        //Colisión con cocodrilos
        else if (compCoco != null && tiempo > tiempoDeInmunidad)
        {
            RecibeDaño(1, other.gameObject);
        }


        //Colisión con cofres (enemigos)
        else if (compCofre != null && tiempo > tiempoDeInmunidad &&
                 compCofre.enemigo && compCofre.abierto)
        {
            RecibeDaño(2, other.gameObject);
        }
        else
        {
            ColisionPichos(other.gameObject);
        }
    }