decreaseHealth() публичный Метод

public decreaseHealth ( double dec ) : void
dec double
Результат void
Пример #1
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            var Player   = GameObject.Find("player");
            var playerRb = Player.GetComponent <Rigidbody>();
            playerRb.velocity = Vector3.zero;
            playerRb.Sleep();
            var memoryObj = GameObject.FindGameObjectWithTag("memory");
            var memory    = memoryObj.GetComponent <transitionMemory>();
            memory.doTransition = false;
            var spawName = memory.nextDoor;


            playerHealthSO.decreaseHealth(1);
            if (playerHealthSO.health > 0)
            {
                Player.GetComponent <PlayerHealth>().hurtEvent.Invoke();
                var door = GameObject.Find(spawName);
                Player.transform.position = door.transform.GetChild(0).position;
            }
            else
            {
                Player.GetComponent <PlayerHealth>().deathEvent.Invoke();
            }
        }
    }
Пример #2
0
    void OnTriggerEnter(Collider col)
    {
        Health health = col.gameObject.GetComponentInParent <Health>();

        if (health == null)
        {
            return;
        }
        health.decreaseHealth(20, myCharacter, Constants.magical, Constants.neutral);
    }
Пример #3
0
    void OnTriggerEnter2D(Collider2D col)
    {
        Character character = col.gameObject.GetComponentInParent <Character>();

        if (character == null || character == myCharacter)
        {
            return;
        }
        Health health = character.GetComponent <Health>();

        health.decreaseHealth(8, myCharacter, Constants.magical, Constants.neutral);
        checkBurn(character);
    }
Пример #4
0
    private void OnTriggerEnter(Collider other)
    {
        if (!isServer)
        {
            return;
        }

        if (other.CompareTag(GameConstants.kPlayerTag))
        {
            Health health = other.GetComponent <Health>();
            health.decreaseHealth(GameConstants.kEnemyDamage);
            onZeroHealth();
        }
    }
Пример #5
0
    //Other functions

    public void autoAttack()      //compute a value between minAttack and maxAttack, and tell the enemy that it is being hurt!
    {
        Debug.Assert(enemy != null);
        if (enemy == null)
        {
            return;
        }
        Health health = enemy.gameObject.GetComponent <Health>();

        Debug.Assert(health != null);
        int extraAttack = (int)Mathf.Floor(Random.value * (float)(maxAttack - minAttack + 1));
        int attack      = minAttack + extraAttack;

        health.decreaseHealth(attack, this, Constants.physical, Constants.neutral);
    }
Пример #6
0
 /**
  * Called from the animator at the time of the attacker's attack.
  * Attempts to strike the object (defender) in front of it.
  *
  * Modifies: decrease's the health of the target.
  */
 public void strikeCurrentTarget(float damage)
 {
     //Debug.Log("Attacking for " + damage.ToString());
     if (currentTarget)
     {
         Health health = currentTarget.GetComponent <Health>() as Health;
         if (!health)
         {
             Debug.LogError("There is no health component associated with " + currentTarget);
         }
         else
         {
             health.decreaseHealth(damage);
         }
     }
 }
Пример #7
0
 private void OnTriggerEnter(Collider other)
 {
     if (!isServer)
     {
         return;
     }
     if (other.CompareTag(GameConstants.kPlayerTag) || other.CompareTag(GameConstants.kEnemyTag))
     {
         Health health = other.GetComponent <Health>();
         if (health != null)
         {
             health.decreaseHealth(mDamage);
         }
         mTargetAcquiredFunc();
         deactivate();
     }
 }
Пример #8
0
    /**
     * Checks to see if the object comes in contact with defender or attacker.
     * Ignores defends, but destroys on hit with attackers. Also causes damage to attacker.
     */
    void OnTriggerEnter2D(Collider2D collider)
    {
        if (collider.GetComponent <Defender>() || collider.GetComponent <Shredder>())
        {
            return;
        }
        Health colliderHealth = collider.GetComponent <Health>() as Health;

        if (colliderHealth)           // If the enemy has a health component, decrement its health.
        {
            colliderHealth.decreaseHealth(damage);
            Destroy(gameObject);
        }
        else
        {
            Debug.LogWarning("Enenmy has no Health component");
        }
    }
Пример #9
0
    public void startSkill()
    {
        SkillManager skillManager = GameObject.FindObjectOfType <SkillManager>();

        skillManager.cancelAllOtherSkills(myCharacter, mySkill);
        mySkill.setCancel(false);
        if (targetCharacter == null)
        {
            cancelSkill();
            return;
        }
        Health health = targetCharacter.gameObject.GetComponent <Health>();

        health.decreaseHealth(-10, myCharacter, Constants.magical, Constants.neutral);
        GameObject heal = Instantiate(healPrefab, targetCharacter.transform.position, Quaternion.identity) as GameObject;

        heal.transform.parent = targetCharacter.transform;
        cancelSkill();
    }
Пример #10
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("Projectile") && !(collision.gameObject.GetComponent <damage>().isFromPlayer))
        {
            int dmg = collision.gameObject.GetComponent <damage>().dmg;

            if (!isInvincible)
            {
                healthSO.decreaseHealth(dmg);
                if (healthSO.health <= 0)
                {
                    deathEvent.Invoke();
                }
                else
                {
                    print("hit, health: " + healthSO.health);
                    hurtEvent.Invoke();
                    isInvincible = true;
                    StartCoroutine(invincible());
                }
            }
        }
    }
Пример #11
0
    void UpdateSpecialMeter()
    {
        //Add meter if you're waiting for it to reload
        if (!canUseSpecial)
        {
            specialMeter.addSpecialMeter(.1f);
            if (specialMeter.curHealth >= 100)
            {
                canUseSpecial          = true;
                specialMeter.curHealth = 100;
                specialMeter.GetComponentInChildren <Image>().color = specialFull;
            }
        }

        //If you're not using your special and your meter isn't full
        //Then you can't use your special
        if (canUseSpecial && !inputManager.getAction2() && specialMeter.curHealth < 100f)
        {
            canUseSpecial = false;
            specialMeter.GetComponentInChildren <Image>().color = specialNotFull;
        }
        else if (specialMeter.curHealth <= 0f)
        {
            canUseSpecial = false;
            specialMeter.GetComponentInChildren <Image>().color = specialNotFull;
        }

        //Santa special
        if (canUseSpecial && inputManager.getAction2() && classID == 1)
        {
            if (!revertSpecialEffects)
            {
                revertSpecialEffects            = true;
                GetComponent <Rigidbody>().mass = .9f;
                maxSpeed = 16f;
                ParticleSystem[] particles = GetComponentsInChildren <ParticleSystem>();
                foreach (ParticleSystem p in particles)
                {
                    p.Play();
                }

                revertSpecialEffects = true;
            }
            specialMeter.decreaseHealth(.6f);
        }
        else if (classID == 1)
        {
            if (revertSpecialEffects)
            {
                GetComponent <Rigidbody>().mass = .45f;
                maxSpeed = 8f;
                ParticleSystem[] particles = GetComponentsInChildren <ParticleSystem>();
                foreach (ParticleSystem p in particles)
                {
                    p.Stop();
                }
                revertSpecialEffects = false;
            }
        }
        //Easter Bunny special
        if (canUseSpecial && inputManager.getAction2Down() && classID == 2)
        {
            EasterBunnyHop();
        }
        //Cupid Special
        if (canUseSpecial && inputManager.getAction2() && classID == 3)
        {
            CupidFlight();
            if (!revertSpecialEffects)
            {
                ParticleSystem[] particles = GetComponentsInChildren <ParticleSystem>();
                foreach (ParticleSystem p in particles)
                {
                    p.Play();
                }
                revertSpecialEffects = true;
            }
        }
        else if (classID == 3)
        {
            if (revertSpecialEffects)
            {
                ParticleSystem[] particles = GetComponentsInChildren <ParticleSystem>();
                foreach (ParticleSystem p in particles)
                {
                    p.Stop();
                }
                revertSpecialEffects = false;
            }
        }
        //Tooth Fairy Special
        if (canUseSpecial && inputManager.getAction2() && classID == 4)
        {
            if (!revertSpecialEffects)
            {
                EnableInvisibility();
                revertSpecialEffects = true;
            }

            specialMeter.decreaseHealth(.8f);
        }
        else if (classID == 4)
        {
            if (revertSpecialEffects)
            {
                DisableInvisibility();
                revertSpecialEffects = false;
            }
        }
    }
Пример #12
0
    // A attack, D defend, H health
    IEnumerator TurnRoutine()
    {
        while (true)
        {
            // Player gets first turn
            if (isPlayer && isAttacking)
            {
                Debug.Log("Player attacking");
                if (Input.GetKey(KeyCode.A))
                {
                    //TODO: do attack animation
                    if (!otherFighter.Defending)
                    {
                        otherHealth.decreaseHealth(attackPower);
                    }
                    otherFighter.Defending = false;

                    if (otherHealth.IsDead())
                    {
                        GameManager.S.ShowGameOver();
                        break;
                    }

                    isAttacking            = false;
                    otherFighter.Attacking = true;
                }
                else if (Input.GetKey(KeyCode.D))
                {
                    //TODO: do defense animation
                    myHealth.ActivateDefense(true);

                    isAttacking            = false;
                    otherFighter.Attacking = true;
                }
                else if (Input.GetKey(KeyCode.H))
                {
                    //TODO: do health animation
                    myHealth.IncreaseHealth(recoverPower);

                    isAttacking            = false;
                    otherFighter.Attacking = true;
                }
                else
                {
                    yield return(null);

                    continue;
                }

                // AI is attacking
            }
            else if (isAttacking)
            {
                Debug.Log("AI Attacking");
                int rand = Random.Range(1, 3);
                switch (rand)
                {
                //TODO: add the animations
                case 1:
                    if (!otherFighter.Defending)
                    {
                        otherHealth.decreaseHealth(attackPower);
                    }
                    otherFighter.Defending = false;
                    break;

                case 2:
                    myHealth.ActivateDefense(true);
                    break;

                default:
                    myHealth.IncreaseHealth(recoverPower);
                    break;
                }
                if (otherHealth.IsDead())
                {
                    GameManager.S.ShowGameOver();
                    break;
                }
                isAttacking            = false;
                otherFighter.Attacking = true;
            }
            else
            {
                Debug.Log("Waiting");
                //Wait until other fighter does something
                yield return(new WaitUntil(() => isAttacking == true));
            }

            yield return(null);
        }
    }
Пример #13
0
    private void setNextDoor()
    {
        print("setNextDoor");
        string debugHelp = "";

        debugHelp += "Door1 " + progress.door1 + " - ";
        debugHelp += "Door2 " + progress.door2 + " - ";
        debugHelp += "Door3 " + progress.door3 + " - ";
        debugHelp += "Door4 " + progress.door4 + " - ";
        debugHelp += "DoorBoss " + progress.doorBoss + " - ";
        print(debugHelp);

        if (!progress.door1)
        {
            progress.door1 = true;
            health.decreaseHealth(1);
            health.decreaseMaxHealth(1);
        }
        else if (!progress.door2)
        {
            progress.door2 = true;
            health.decreaseHealth(2);
            health.decreaseMaxHealth(2);
        }
        else if (!progress.door3)
        {
            progress.door3 = true;
            health.decreaseHealth(2);
            health.decreaseMaxHealth(2);
        }
        else if (!progress.door4)
        {
            progress.door4 = true;
            health.decreaseHealth(2);
            health.decreaseMaxHealth(2);
        }
        else if (!progress.doorBoss)
        {
            health.decreaseHealth(3);
            health.decreaseMaxHealth(3);
            progress.doorBoss = true;
        }

        //switch (progress.finishedLevelCount)
        //{
        //    case 1:
        //        progress.door1 = true;
        //        //    health.decreaseHealth(1);
        //        //    health.decreaseMaxHealth(1);
        //        break;
        //    case 2:
        //        break;
        //    case 3:
        //        break;
        //    case 4:
        //        break;
        //}

        var player   = GameObject.FindGameObjectWithTag("Player");
        var healthUi = player.GetComponentInChildren <HeartUI>();

        healthUi.UpdateHearts();
    }