Example #1
0
    public override void Die()
    {
        //only die once
        if (dead)
        {
            return;
        }
        dead = true;

        //death call to player
        PlayerClasses pClass = FindObjectOfType <PlayerClasses>();

        pClass.enemyKilled();

        //Randomly select a bait from dropTable based on dropOdds and give to player
        PlayerStats pStats    = pClass.GetComponentInParent <PlayerStats>();
        float       dropValue = Random.Range(0, dropRange);
        int         dropIndex = 0;

        if (dropValue > 0)
        {
            dropIndex = -1;
            while (dropValue > 0)
            {
                dropIndex++;
                dropValue -= dropOdds[dropIndex];
            }
        }
        if (dropTable[dropIndex] >= 0)
        {
            pStats.baitInventory.addBait(dropTable[dropIndex]);
        }


        myBase.myCombat.OnDeath();
        if (numberOfTimesToRespawn == 0)
        {
            Destroy(gameObject);
        }
        else
        {
            if (numberOfTimesToRespawn != -1)
            {
                numberOfTimesToRespawn--;
            }
            this.transform.position = spawnPoint;
            currentHP       = maxHP;
            healthbar.value = 1;
        }
    }