Exemple #1
0
    void receiveAttack(int dmg)
    {
        hp -= dmg;
        Debug.Log("Was dealt " + dmg + " damage and is now at " + hp + " hp");

        if (hp <= 0)
        {
            Debug.Log("DEAD");
            handler = new RemoveFromPlay(this, player);
            handler.affect();
        }
    }
        void Update()
        {
            if (removeAfterDelay) {
                delayTimer += Time.deltaTime;

                if (delayTimer > DELAY_CONSTANT) {

                    handler = new RemoveFromPlay (this, player);
                    handler.affect ();
                    removeAfterDelay = false;
                    delayTimer = 0;
                }

                Debug.Log (Time.deltaTime);

            }

            //Change text on card
            transform.Find ("AttackText").GetComponent<TextMesh> ().text = dmg.ToString ();
            transform.Find ("HealthText").GetComponent<TextMesh> ().text = hp.ToString ();
            if (hp < maxHP) {
                transform.Find ("HealthText").GetComponent<MeshRenderer> ().material.color = Color.red;
            } else if (hp > maxHP) {
                transform.Find ("HealthText").GetComponent<MeshRenderer> ().material.color = Color.green;
            } else if (hp == maxHP) {
                transform.Find ("HealthText").GetComponent<MeshRenderer> ().material.color = Color.white;
            }
            if (dmg < naturalDmg) {
                transform.Find ("AttackText").GetComponent<MeshRenderer> ().material.color = Color.red;
            } else if (dmg > naturalDmg) {
                transform.Find ("AttackText").GetComponent<MeshRenderer> ().material.color = Color.green;
            } else if (dmg == naturalDmg) {
                transform.Find ("AttackText").GetComponent<MeshRenderer> ().material.color = Color.white;
            }
            if (canAttackNow) {
                transform.Find ("DoneText").GetComponent<TextMesh> ().text = "";
            } else if (!canAttackNow) {
                transform.Find ("DoneText").GetComponent<TextMesh> ().text = "Done";
            }
            //If damaged
            if (dmgTimer > 0) {
                dmgTimer--;
            } else {
                transform.Find ("DamageText").GetComponent<TextMesh> ().text = "";
            }
            //Moving
            moving ();
        }