Exemplo n.º 1
0
    //------------------------------------------------------------------------------------------------------------------

    /*
     * METODO QUE SE EJECUTA CADA CIERTO TIEMPO FIJO EN LUGAR DE CADA FOTOGRAMA (OPTIMO PARA LA GESTION DE FISICAS)
     */
    public void FixedUpdate()
    {
        //Comprobar si estamos cerca de la planta y estamos vivos
        if (Physics2D.OverlapArea(puntoA.position, puntoB.position, mascaraPlanta) && estadoJugador.getVida() > 0)
        {
            //Es la primera vez que entramos en la planta
            if (gestionPlantas.getEstoyCercaPlanta() == false)
            {
                //Marcamos la planta como ocupada
                gestionPlantas.ocuparPlanta(true);
            }
        }
        else
        {
            //Es la primera vez que salimos de la planta
            if (gestionPlantas.getEstoyCercaPlanta())
            {
                //Marcamos la planta como no ocupada
                gestionPlantas.ocuparPlanta(false);
            }
        }

        //Si estoy cerca de la planta
        if (gestionPlantas.getEstoyCercaPlanta())
        {
            //Dependiendo de si la planta esta ocupada mostramos el boton o no
            gestorInterfaz.estadoBotonPlanta(!gestionPlantas.getPlantaOcupada());
        }
        else
        {
            //Si no estoy cerca de la planta directamente no se muestra en boton
            gestorInterfaz.estadoBotonPlanta(false);
        }
    }
Exemplo n.º 2
0
    //------------------------------------------------------------------------------------------------------------------

    /*
     * METODO QUE SE EJECUTA REPETIDAMENTE CADA FOTOGRAMA DE LA EJECUCION
     */
    void Update()
    {
        //Actuamos si el script pertenece a nuestro jugador
        if (pView.IsMine)
        {
            //Actualizar vida
            if (txtVida != null)
            {
                txtVida.text = "" + Mathf.Clamp(vidaAux, 0, vida);
            }

            ///////////////////////////////// MUERTE //////////////////////////////////
            //Si la vida es igual a 0 llamamos al metodo para morir
            if (vidaAux <= 0)
            {
                gestionPlantas.ocuparPlanta(false);
                pView.RPC("morir_RPC", Photon.Pun.RpcTarget.AllBuffered);
            }

            //////////////////////////// COGER LA PLANTA /////////////////////////////
            //Actuar mientras tengamos la planta
            if (estado == 3)
            {
                //Primera ejecucion con la planta
                if (iniciarCargaEnergia)
                {
                    //Ejecutar una sola vez
                    iniciarCargaEnergia = false;
                    //Establecer como cargando
                    iconoEnergia.GetComponent <Animator>().SetBool("Cargando", true);
                    //Reproducir sonido
                    pView.RPC("sonidoPlanta_RPC", Photon.Pun.RpcTarget.AllBuffered, true);
                }

                //Sumar el tiempo con la planta
                tiempoEnergia += Time.deltaTime;

                //Comprobar si se alcanza una recarga
                if (tiempoEnergia >= tiempoRecarga)
                {
                    iconoEnergia.GetComponent <Animator>().SetBool("Cargando", false);
                    tiempoEnergia = 0;                                //Resetear el tiempo de energia
                    contEnergia  += energiaPorRecarga;                //Sumar la energia de la recarga
                    controlJuego.setMiEnergia(contEnergia);           //Establecer valor en el contador del control de juego
                    txtEnergia.text     = contEnergia.ToString("f0"); //Actualizar marcador
                    iniciarCargaEnergia = true;
                }

                //Si no tenemos la planta
            }
            else
            {
                //Detener animacion cargando
                iconoEnergia.GetComponent <Animator>().SetBool("Cargando", false);
                //Detener sonido
                pView.RPC("sonidoPlanta_RPC", Photon.Pun.RpcTarget.AllBuffered, false);
                //Establecer variables
                tiempoEnergia       = 0;
                iniciarCargaEnergia = true;
            }
        }
    }