コード例 #1
0
    //功能:UpdateGUI
    //更新生命值GUI、子彈GUI、火箭彈GUI的狀況
    void UpdateGUI()
    {
        // Update health gui
        // The health gui is rendered using a overlay texture which is scaled down based on health
        // - Calculate fraction of how much health we have left (0...1)
        var healthFraction = Mathf.Clamp01(hitPoints / maximumHitPoints);

        hpRect      = healthGUI.pixelInset;
        hpRect.xMax = healthGUI.pixelInset.xMin + healthGUIWidth * healthFraction;

        // - Adjust maximum pixel inset based on it
        healthGUI.pixelInset = hpRect;

        // Update machine gun gui
        // Machine gun gui is simply drawn with a bullet counter text
        if (machineGun)
        {
            bulletGUI.text = machineGun.GetBulletsLeft().ToString() + "/" + machineGun.Getclips().ToString();
        }

        // Update rocket gui
        // This is changed from the tutorial PDF. You need to assign the 20 Rocket textures found in the GUI/Rockets folder
        // to the RocketTextures property.
        if (rocketLauncher)
        {
            rocketGUI.UpdateRockets((int)rocketLauncher.ammoCount);
        }
    }