Esempio n. 1
0
    public void takeDamage(int damage)
    {
        StartCoroutine("SpriteBlink");
        ofs = new Vector3(Random.Range(-.6f, 1f), Random.Range(.25f, 1f), 0);
        TextMesh dmgtxt = floatingTextPrefab.GetComponent <TextMesh>();

        dmgtxt.color = Color.white;

        dmgtxt.text = damage.ToString();
        GameObject text = Instantiate(floatingTextPrefab, transform.position + ofs, Quaternion.identity);

        Destroy(text, .77f);
        health -= damage;

        if (health <= 20)
        {
            spr.color = new Color32(255, 25, 25, 165);
        }
        else if (health <= 50)
        {
            spr.color = new Color32(255, 100, 100, 190);
        }
        if (health <= 0)
        {
            if (gameObject.name == "Rock")
            {
                FindObjectOfType <AudioManager>().Stop("Rocky");
            }
            else if (gameObject.name == "range")
            {
                FindObjectOfType <AudioManager>().Stop("BMW");
            }
            Destroy(transform.parent.gameObject);
            DestroyableWall.KilledEnemies();
            //FOR NOW MONSTERS ONLY WILL DROP CARDS. THE MOD LOOT WILL COME FROM THE ONE CHEST TO SHOW OFF THAT


            //choose between card or curcuitry upgrade
            int rand = 1;
            //Random.Range(0, 8);
            //if (rand > 5)
            //{
            //    Instantiate(circuitLootPrefab, transform.position, Quaternion.identity);
            //}
            //else
            if (rand >= 0)
            {
                //DROPS TWO ITEMS, PICK UP ONE AND ADD TO HAND, DESTROY OTHER CARD
                //ADD way to destroy other gameobject
                //Vector2 lootdrop = new Vector2(transform.position.x - 3, transform.position.y);
                Vector2    lootdrop = new Vector2(player.transform.position.x - 3, player.transform.position.y);
                GameObject o        = Instantiate(BeamLootPrefab, lootdrop, Quaternion.identity);
                cm.lootCount++;
                o.name = cm.lootCount.ToString();
                Card loot;
                loot = cm.lootDeck[cm.loot()];
                o.GetComponent <CardLoot>().LoadCard(loot);

                lootdrop = new Vector2(player.transform.position.x + 3, player.transform.position.y);
                GameObject o2 = Instantiate(BeamLootPrefab, lootdrop, Quaternion.identity);
                cm.lootCount++;
                o2.name = cm.lootCount.ToString();
                Card loot2;
                loot2 = cm.lootDeck[cm.loot()];
                o2.GetComponent <CardLoot>().LoadCard(loot2);
            }
            //Player health adjustements
            BasicMovment p = GameObject.FindGameObjectWithTag("Player").GetComponent <BasicMovment>();
            if (p.curHealth < p.maxHealth && p.curHealth >= 90)
            {
                p.curHealth = p.maxHealth;
                float calcHealth = p.curHealth / p.maxHealth;
                p.SetHealthBar(calcHealth);
            }
            else if (p.curHealth < 90)
            {
                p.curHealth += 10;
                float calcHealth = p.curHealth / p.maxHealth;
                p.SetHealthBar(calcHealth);
            }
        }
    }
Esempio n. 2
0
    public void takeDamage(int damage)
    {
        ofs = new Vector3(Random.Range(-.6f, 1f), Random.Range(.25f, 1f), 0);
        TextMesh dmgtxt = floatingTextPrefab.GetComponent <TextMesh>();

        dmgtxt.text = damage.ToString();
        GameObject text = Instantiate(floatingTextPrefab, transform.position + ofs, Quaternion.identity);

        Destroy(text, .77f);
        health -= damage;
        if (health <= 20)
        {
            spr.color = new Color32(255, 25, 25, 165);
        }
        else if (health <= 50)
        {
            spr.color = new Color32(255, 100, 100, 190);
        }
        if (health <= 0)
        {
            if (gameObject.name == "Rock")
            {
                FindObjectOfType <AudioManager>().Stop("Rocky");
            }
            else if (gameObject.name == "range")
            {
                FindObjectOfType <AudioManager>().Stop("BMW");
            }
            Destroy(gameObject);



            //choose between card or curcuitry upgrade
            int rand = Random.Range(0, 6);
            if (rand > 5)
            {
                Instantiate(circuitLootPrefab, transform.position, Quaternion.identity);
            }
            else if (rand >= 0)
            {
                Vector2    lootdrop = new Vector2(transform.position.x - 2, transform.position.y + 1);
                GameObject o        = (GameObject)Instantiate(BeamLootPrefab, lootdrop, Quaternion.identity);
                cm.lootCount++;
                o.name = cm.lootCount.ToString();
                Card loot;
                loot = cm.lootDeck[cm.loot()];
                o.GetComponent <CardLoot>().LoadCard(loot);

                lootdrop = new Vector2(transform.position.x + 2, transform.position.y + 1);
                GameObject o2 = (GameObject)Instantiate(BeamLootPrefab, lootdrop, Quaternion.identity);
                cm.lootCount++;
                o2.name = cm.lootCount.ToString();
                Card loot2;
                loot2 = cm.lootDeck[cm.loot()];
                o2.GetComponent <CardLoot>().LoadCard(loot2);
            }
            //PLAY HEALTH ADJUSTMENTS
            BasicMovment p = GameObject.FindGameObjectWithTag("Player").GetComponent <BasicMovment>();
            if (p.curHealth < p.maxHealth && p.curHealth >= 90)
            {
                p.curHealth = p.maxHealth;
                float calcHealth = p.curHealth / p.maxHealth;
                p.SetHealthBar(calcHealth);
            }
            else if (p.curHealth < 90)
            {
                p.curHealth += 10;
                float calcHealth = p.curHealth / p.maxHealth;
                p.SetHealthBar(calcHealth);
            }
        }
    }