示例#1
0
    public void GetData()
    {
        Debug.Log("Saving player data");
        levelCounter++;

        //Save player health
        BarController player = GameObject.Find("Captain").GetComponent <BarController>();

        playerHealth = player.GetHealth();

        //Get Coins
        playerCoins = player.GetCoins();

        //Get Resources
        playerResources = player.GetResources();

        //Get Score
        playerScore = player.GetScore();

        //Get Crafting Cost
        playerCraftingCost = player.craftingCost;

        //Gey Key
        playerKey = player.foundKey;

        //Get Player Revived State
        playerRevived = player.GetPlayerRevived();

        //Get Extra Stats
        playerUpgradedAttack  = player.upgradedDamage;
        playerUpgradedDefence = player.upgradedDefence;
        playerUpgradedHealth  = player.upgradedHealth;
        playerUpgradedSpeed   = player.upgradedSpeed;

        //Get Challenge counter
        playerChallengeCounter = player.challengeCounters;

        //Get Inventory
        PlayerInventory inventoryScript = GameObject.Find("Captain").GetComponent <PlayerInventory>();

        playerInventory = inventoryScript.slotID;
        this.slotID     = inventoryScript.slotID;
        this.slotValue  = inventoryScript.slotValue;
        this.slotName   = inventoryScript.slotName;
        this.slotDesc   = inventoryScript.slotDesc;
        this.slotSprite = inventoryScript.slotSprite;
        this.slotType   = inventoryScript.slotType;
        this.slotStack  = inventoryScript.slotStack;
        this.slotIcon   = inventoryScript.slotIcon;

        //Get Villager
        villageState = GameObject.Find("PickUpRange").GetComponent <PlayerInteract>().UnlockedVillagers;
    }
    void Dead()
    {
        //Give player resource and prepare for reset
        //health = original_health;
        //reset_time = original_reset_time;
        audioS.PlayOneShot(collect, 1f);
        BarController barcontroller  = GameObject.Find("Captain").GetComponent <BarController>();
        int           resourceAmount = 2 + Random.Range(0, CloudVariables.Values[7] + 2);

        barcontroller.resource_points += resourceAmount;
        barcontroller.SetScore(barcontroller.GetScore() + Random.Range(2, 7));
        if (barcontroller.GetHorseShoe() == true)
        {
            resourceAmount += 2;
            barcontroller.resource_points += 2;
        }
        barcontroller.challengeCounters[3] += resourceAmount;
        this.gameObject.SetActive(false);
    }
    // Update is called once per frame
    void Update()
    {
        damageTaken = barScript.damageDone;

        #region Check if Dead
        if (health <= 0)
        {
            if (!_isBoss)
            {
                doDamageScript.enabled = false;
            }
            if (_isDead == false)
            {
                if (!_isBoss)
                {
                    barScript.SetScore(barScript.GetScore() + Random.Range(2, 7));
                    deathAnim.DOPlayById("DEATH");
                    float pickReward = Random.value;
                    if (pickReward >= 0.1f)
                    {
                        Loot(0);

                        if (barScript.GetGoldTooth() == true)
                        {
                            Loot(0);
                        }
                    }
                    else
                    {
                        Loot(1);
                    }
                }
                else
                {
                    barScript.SetScore(barScript.GetScore() + 10);
                    Loot(2);
                }

                //If boss do instant death timer else apply 2 seconds of death time
                if (_isBoss)
                {
                    StartCoroutine("DeathTimer", 0f);
                }
                else
                {
                    StartCoroutine("DeathTimer", 1.5f);
                }
                //audioS.PlayOneShot(deathSound, 1.0F);
                _isDead = true;
            }
        }
        #endregion

        #region Flash when enemy is hit
        if (flashTime > 0)
        {
            flashTime -= Time.deltaTime;
            flash.SetActive(true);
        }
        else if (flashTime <= 0)
        {
            flashTime = 0;
            flash.SetActive(false);
        }
        #endregion
    }