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