Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        // hp
        int   n  = 0;
        float hp = thruster.GetHP();

        if (hp <= 1.1f)
        {
            n = (int)Mathf.Floor(overchargeFrame * (hp / 1.1f));
        }
        else
        {
            n = overchargeFrame + (int)Mathf.Floor((maxFrame - overchargeFrame) * (hp - 1.1f) / .9f);
        }
        string  hpTexName = "ThrusterTopHUD/thruster-top-hud-hp-" + n;
        Texture hpTex     = (Texture)Resources.Load(hpTexName);

        hpRenderer.material.mainTexture = hpTex;

        // energy
        n = 0;
        float energy = thruster.GetEnergy();

        if (energy <= 1.1f)
        {
            n = (int)Mathf.Floor(overchargeFrame * (energy / 1.1f));
        }
        else
        {
            n = overchargeFrame + (int)Mathf.Floor((maxFrame - overchargeFrame) * (energy - 1.1f) / .9f);
        }
        string  energyTexName = "ThrusterTopHUD/thruster-top-hud-energy-" + n;
        Texture energyTex     = (Texture)Resources.Load(energyTexName);

        energyRenderer.material.mainTexture = energyTex;
    }
Beispiel #2
0
    void Update()
    {
        if (!isLocalPlayer)
        {
            thrusterTopLeft.SetEnergy(_e0);
            thrusterTopLeft.SetHP(_hp0);

            thrusterBottomLeft.SetEnergy(_e1);
            thrusterBottomLeft.SetHP(_hp1);

            thrusterBottomRight.SetEnergy(_e2);
            thrusterBottomRight.SetHP(_hp2);

            thrusterTopRight.SetEnergy(_e3);
            thrusterTopRight.SetHP(_hp3);

            return;
        }

        if (IsLocked)
        {
            return;
        }

        bool changed = false;

        // Substract
        if (Input.GetKeyDown("a"))
        {
            energyTank += Mathf.Min(
                thrusterTopLeft.SubtractEnergy(energyInc),
                energyTankMax
                );
            changed = true;
        }
        if (Input.GetKeyDown("s"))
        {
            energyTank += Mathf.Min(
                thrusterBottomLeft.SubtractEnergy(energyInc),
                energyTankMax
                );
            changed = true;
        }

        if (Input.GetKeyDown("d"))
        {
            energyTank += Mathf.Min(
                thrusterBottomRight.SubtractEnergy(energyInc),
                energyTankMax
                );
            changed = true;
        }
        if (Input.GetKeyDown("f"))
        {
            energyTank += Mathf.Min(
                thrusterTopRight.SubtractEnergy(energyInc),
                energyTankMax
                );
            changed = true;
        }

        // Add
        if (Input.GetKeyDown("q") &&
            energyTank >= energyInc)
        {
            energyTank -= thrusterTopLeft.AddEnergy(energyInc);
            changed     = true;
        }
        if (Input.GetKeyDown("w") &&
            energyTank >= energyInc)
        {
            energyTank -= thrusterBottomLeft.AddEnergy(energyInc);
            changed     = true;
        }

        if (Input.GetKeyDown("e") &&
            energyTank >= energyInc)
        {
            energyTank -= thrusterBottomRight.AddEnergy(energyInc);
            changed     = true;
        }
        if (Input.GetKeyDown("r") &&
            energyTank >= energyInc)
        {
            energyTank -= thrusterTopRight.AddEnergy(energyInc);
            changed     = true;
        }

        if (changed)
        {
            CmdUpdateThrusters(
                thrusterTopLeft.GetEnergy(),
                thrusterTopLeft.GetHP(),

                thrusterBottomLeft.GetEnergy(),
                thrusterBottomLeft.GetHP(),

                thrusterBottomRight.GetEnergy(),
                thrusterBottomRight.GetHP(),

                thrusterTopRight.GetEnergy(),
                thrusterTopRight.GetHP()
                );
        }

        RaycastHit hit;

        if (Physics.Raycast(transform.position, Vector3.down, out hit, 10.0f))
        {
            if (hit.transform.tag == "Boxes")
            {
                thrusters.ForEach((thruster) => thruster.RecoverDamage(1 * Time.deltaTime));

                float availableTank = 4f - energyTank;
                energyTank += Mathf.Min(1f * Time.deltaTime, availableTank);
            }
        }

        int n = (int)(40 * (energyTank / 4f));

        n = Mathf.Min(n, 40);
        string  hpTexName = "TankHUD/tank-hud-" + n;
        Texture hpTex     = (Texture)Resources.Load(hpTexName);

        tankHUD.material.mainTexture = hpTex;
    }