Beispiel #1
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;
            }
        }
    }