コード例 #1
0
    void upgrade_if_better(GameObject crate)
    {
        CrateContents   cc  = crate.GetComponent <CrateContents>();
        ShipStatsScript sss = GetComponent <ShipStatsScript>();

        if (cc.type == Constants.UpgradeTypes.topSpeed)
        {
            if (cc.value + sss.topSpeed > sss.topSpeed)
            {
                sss.topSpeed = cc.value;
            }
        }
        else if (cc.type == Constants.UpgradeTypes.SHIELD)
        {
            if (cc.value > sss.shield)
            {
                sss.shield = cc.value;
            }
        }
        else if (cc.type == Constants.UpgradeTypes.ACCELERATION)
        {
            if (cc.value > sss.acceleration)
            {
                sss.acceleration = cc.value;
            }
        }
        else if (cc.type == Constants.UpgradeTypes.TURNSPEED)
        {
            if (cc.value > sss.turnspeed)
            {
                sss.turnspeed = cc.value;
            }
        }
    }
コード例 #2
0
    // Remember, this value is in the range 0.0 to 1.0 (with a lot more low numbers than high numbers)
    void put_contents_in_crate(GameObject newCrate, Constants.UpgradeTypes type, float value)
    {
        // The contents of the crate are stored in its CrateContents script, so we have to
        //  get a reference to it...
        CrateContents cc = newCrate.GetComponent <CrateContents>();

        // Setting the type is easy!
        cc.type = type;

        // But how we do the value depends on the range that it can take, and _that_ depends
        //  on what type of upgrade it is...
        // Each "leg" of this if ... else is going to work out the correct value for
        //  the relevant type of upgrade. But where will we get the correct constants
        //  to send to de_normalise_value(...) ?

        if (type == Constants.UpgradeTypes.ACCELERATION)
        {
            cc.value = de_normalise_value(value, Constants.DEFAULTSHIPACCELERATION, Constants.MAXIMUMSHIPACCELERATION);
        }
        else if (type == Constants.UpgradeTypes.topSpeed)
        {
            cc.value = de_normalise_value(value, Constants.DEFAULTMAXSHIPSPEED, Constants.MAXIMUMSHIPSPEED);
        }
        else if (type == Constants.UpgradeTypes.SHIELD)
        {
            cc.value = de_normalise_value(value, 0f, Constants.MAXIMUMSHIPSHIELD);
        }
        else if (type == Constants.UpgradeTypes.TURNSPEED)
        {
            cc.value = de_normalise_value(value, Constants.DEFAULTTURNSPEED, Constants.MAXIMUMTURNSPEED);
        }
    }