Ejemplo n.º 1
0
    void DoDamage()
    {
        Debug.Log("Explosion: DoDamage");

        Collider[] objectsInRange = Physics.OverlapSphere(transform.position, Radius);
        foreach (Collider collider in objectsInRange)
        {
            Health healthComponent = collider.GetComponent <Health>();
            if (healthComponent != null)
            {
                // Don't affect the owner unless specified
                if (collider.gameObject != owner.gameObject)
                {
                    healthComponent.AddHealth(-Damage);
                }
                else
                {
                    if (AffectOwner)
                    {
                        healthComponent.AddHealth(-Damage);
                    }
                }
            }
        }

        startExpire = true;
    }
Ejemplo n.º 2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Collectable")
        {
            Instantiate(pickupParticles, collision.transform.position, Quaternion.identity);
            AudioManager.PlaySound(pickupSound);
            Score.AddScore(collision.GetComponent <Collectable>().GetValue());
            Destroy(collision.gameObject);
        }

        if (collision.gameObject.tag == "Obstacle" && !forceFieldPowerUp.gameObject.activeSelf)
        {
            Health.SubtractHealth(collision.GetComponent <Obstacle>().GetDamage());
            Destroy(collision.gameObject);
        }

        if (collision.gameObject.tag == "HealthItem")
        {
            Instantiate(pickupParticles, collision.transform.position, Quaternion.identity);
            AudioManager.PlaySound(healthSound);
            Health.AddHealth(collision.GetComponent <HealthItem>().GetValue());
            Destroy(collision.gameObject);
        }

        if (collision.gameObject.tag == "PowerUp")
        {
            Instantiate(pickupParticles, collision.transform.position, Quaternion.identity);
            AudioManager.PlaySound(powerupSound);
            forceFieldPowerUp.gameObject.SetActive(true);
        }
    }
 private void OnTriggerEnter2D(Collider2D collider)
 {
     if (collider.gameObject.CompareTag("Heart"))
     {
         collider.gameObject.SetActive(false);
         _characterUi.AddHealth(10);
     }
     if (collider.gameObject.CompareTag("SuperCoin"))
     {
         _supercoin++;
         collider.gameObject.SetActive(false);
     }
     if (collider.gameObject.CompareTag("Coin"))
     {
         _coin += 1 + _upgradeValue;
         collider.gameObject.SetActive(false);
     }
     if (collider.gameObject.CompareTag("Spike"))
     {
         collider.gameObject.SetActive(false);
         _characterUi.DealDamage(6);
     }
     if (collider.gameObject.CompareTag("DoubleJump"))
     {
         _canDoubleJump = true;
         StartCoroutine(SetTextCheckpoint());
     }
 }
Ejemplo n.º 4
0
    private void Spawn()
    {
        for (int i = 1; i <= lanesToSpawn; ++i)
        {
            int randomNumber = Random.Range(1, 6);
            if (i != randomNumber)
            {
                continue;
            }

            Vector2    spawnPosition = new Vector2(11, i);
            BoardPiece newAttacker   = Instantiate(
                attackers[Random.Range(0, attackerTier)],
                spawnPosition,
                Quaternion.identity
                );

            Health newAttackerHealth = newAttacker.GetComponent <Health>();
            if (newAttackerHealth)
            {
                newAttackerHealth.AddHealth(
                    difficultyLevel
                    * difficultyMultiplier
                    * difficultyMultiplier
                    );
            }

            newAttacker.transform.SetParent(transform);
            levelController.AttackerSpawned();
        }
    }
Ejemplo n.º 5
0
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.Escape))
     {
         Application.Quit();
     }
     if (Input.GetKeyDown(KeyCode.O))
     {
         SceneManager.LoadScene(0);
     }
     if (Input.GetKeyDown(KeyCode.P))
     {
         if (gametime.PlayTime == 0)
         {
             gametime.PlayTime = 1;
             cheat             = false;
         }
         else if (gametime.PlayTime == 1)
         {
             gametime.PlayTime = 0;
             cheat             = true;
         }
     }
     if (cheat)
     {
         if (Input.GetKeyDown(KeyCode.UpArrow))
         {
             hp.AddHealth(999);
         }
     }
 }
Ejemplo n.º 6
0
    public void TestHealthNotGoAboveOne()
    {
        // Arrange
        Health h = new Health();
        float  expectedResult = 1;

        // Act
        h.AddHealth(0.1f);
        h.AddHealth(0.5f);
        h.AddHealth(1);
        h.AddHealth(5);
        float result = h.GetHealth();

        // Assert
        Assert.AreEqual(expectedResult, result);
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        FireBallController fireBall = other.GetComponent <FireBallController>();

        if (fireBall)
        {
            GetComponent <Rigidbody2D>().AddForce(new Vector2(0, 300));
            health.TakeDamage(30);
        }

        BulletController bullet = other.GetComponent <BulletController>();

        if (bullet)
        {
            GetComponent <Rigidbody2D>().AddForce(new Vector2(0, 300));
            health.TakeDamage(30);
        }
        if (other.tag == "Asteroid")
        {
            health.TakeDamage(30);
        }
        if (other.tag == "health")
        {
            health.AddHealth(25);
            Destroy(other.gameObject);
        }
    }
Ejemplo n.º 8
0
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag("Collectable"))
     {
         Destroy(other.gameObject);
         if (OnCollectablePicked != null)
         {
             OnCollectablePicked();
         }
     }
     else if (other.gameObject.CompareTag("Key"))
     {
         Destroy(other.gameObject);
         haveKey = true;
         keyBar.UpdateKeyBar(haveKey);
     }
     else if (other.gameObject.CompareTag("Door") && haveKey)
     {
         Destroy(other.gameObject);
         haveKey = false;
         keyBar.UpdateKeyBar(haveKey);
     }
     else if (other.gameObject.CompareTag("Fruit"))
     {
         health.AddHealth(20);
         other.GetComponent <FruitBehaviour>().eaten();
     }
 }
        private void AddHealth()
        {
            int points = generator.GenerateNumber(characterClass.GetHitDieSize());

            health.AddHealth(points);
            baseStats.AddHealth(points);
        }
Ejemplo n.º 10
0
        public string followOrder(string[] parameters)
        {
            if (parameters.Count() == 0)
            {
                return("Co mám sníst? Musíš zadat název pochutiny");
            }

            string foodName = parameters[0];
            Thing  food     = inventory.getThingByName(foodName);

            if (food != null)
            {
                if (food.IsEatable)
                {
                    inventory.deleteThing(foodName);
                    health.AddHealth(1);
                    return("Snědl jsi: " + foodName);
                }
                else
                {
                    return("Tato věc není k jídlu");
                }
            }
            else
            {
                return("Toto není ve tvém inventáři");
            }
        }
Ejemplo n.º 11
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("Wall") || other.gameObject.name == "Player")
        {
            playBoltStrike();
            Destroy(gameObject);
            if (Health.healthcount > 0)
            {
                Health.AddHealth(-10);
            }
        }

        if (other.gameObject.CompareTag("Trap"))
        {
            playExplosion();
            Destroy(gameObject);
            ScoreManager.AddScore(2);
        }

        if (other.gameObject.CompareTag("Bullet"))
        {
            playExplosion();
            Destroy(gameObject);
            Destroy(other.gameObject);
            ScoreManager.AddScore(2);
        }

        if (other.gameObject.CompareTag("Grenade"))
        {
            playExplosion();
            Destroy(gameObject);
            ScoreManager.AddScore(2);
        }
    }
 public override void AddService()
 {
     base.AddService();
     health.AddHealth(this);
     health.addLocalHealth += DoEffect;
     health.servicePayment += PayForService;
 }
Ejemplo n.º 13
0
    public void OnOpen()
    {
        player       = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerManager>();
        playerHealth = GameObject.FindGameObjectWithTag("Player").GetComponent <Health>();

        System.Random random = new System.Random(System.DateTime.Now.Millisecond);
        int           num    = random.Next(0, 100);

        if (num > chanceForDamage)
        {
            num = random.Next(minDMGincrease, maxDMGincrease);
            player.AddDamage(num);
        }

        num = random.Next(0, 100);

        if (num > chanceForBaseHealth)
        {
            num = random.Next(minHealthIncrease, maxHealthIncrease);
            playerHealth.AddBaseHealth(num);
        }

        num = random.Next(0, 100);

        if (num > chanceForHealth)
        {
            num = random.Next(minBaseHealthIncrease, maxBaseHealthIncrease);
            playerHealth.AddHealth(num);
        }



        Destroy(this.gameObject);
    }
Ejemplo n.º 14
0
    void OnCollisionEnter2D(Collision2D collis)
    {
        if (collis.gameObject.tag == "Candy")
        {
            Destroy(collis.gameObject);
            AddScore();
            ChangeColor();
        }

        if (collis.gameObject.tag == "GreenD")
        {
            Destroy(collis.gameObject);
            ScaleCatcher();
        }

        if (collis.gameObject.tag == "RedD")
        {
            Destroy(collis.gameObject);
            DestroyCandies();
        }

        if (collis.gameObject.tag == "Health")
        {
            Destroy(collis.gameObject);
            newHealth.AddHealth();
        }
    }
Ejemplo n.º 15
0
    public void TestPointTwoAfterAddPointOneTwiceAfterKill()
    {
        // Arrange
        Health h              = new Health();
        float  healthToAdd    = 0.1f;
        float  expectedResult = 0.2f;

        // Act
        h.KillCharacter();
        h.AddHealth(healthToAdd);
        h.AddHealth(healthToAdd);
        float result = h.GetHealth();


        // Assert
        Assert.AreEqual(expectedResult, result);
    }
Ejemplo n.º 16
0
 void HealPlayer(int count, float unit)
 {
     if (PlayerHealth == null)
     {
         return;
     }
     PlayerHealth.AddHealth(unit * count);
 }
Ejemplo n.º 17
0
 public void OnCollisionStay(Collision other)
 {
     if (other.gameObject.name == "Player")
     {
         Health healthScript = other.gameObject.GetComponent <Health>();
         healthScript.AddHealth(-0.1f);
     }
 }
Ejemplo n.º 18
0
    public override bool WasHit(float wepStrength)
    {
        float hitStrength = 100 * wepStrength / defence;

        _health.GotHit(hitStrength);
        _health.AddHealth(hitStrength);
        return(false);
    }
Ejemplo n.º 19
0
    public DamageInfo TakeDamage(DamageInfo damageInfo, ICombatUnit other)
    {
        damageInfo = ((ITakeDamageDecorator)this).Decorate(damageInfo);

        damageInfo.Damage = Health.AddHealth(damageInfo.Damage);

        if (damageInfo.Damage == 0)
        {
            return(damageInfo);
        }

        Debug.Log("<color=red>" + gameObject.name + " Took Damage: " + damageInfo.Damage + " Cur Health: " + Health.CurValue + "</color>");

        FireOnTookDamage(damageInfo, other);

        return(damageInfo);
    }
Ejemplo n.º 20
0
 // Update is called once per frame
 private void AddHealth()
 {
     if (ScoreManager.storageA >= Healthprice && Health.healthcount < Health.maxhealth)
     {
         ScoreManager.AddScore(-Healthprice);
         Health.AddHealth(10);
     }
 }
Ejemplo n.º 21
0
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.name.Contains("Bullet"))
     {
         Health healthScript = GetComponent <Health>();
         healthScript.AddHealth(-1f);
         Destroy(other.gameObject);
     }
 }
Ejemplo n.º 22
0
    private void OnParticleCollision(GameObject other)
    {
        Health otherHealth = other.GetComponent <Health>();

        if (otherHealth != null)
        {
            otherHealth.AddHealth(Damage);
        }
    }
Ejemplo n.º 23
0
 void OnCollisionEnter(Collision collision)
 {
     if (!injured)
     {                                //when player collides with enemy
         healthscript.AddHealth(-30); //reduce health
         healthSlider.value = healthscript.CaculateHeathOnSlider();
         injured            = true;
     }
 }
Ejemplo n.º 24
0
    private void Update()
    {
        if (Time.time > timestamp)
        {
            playerHealth.AddHealth(-damagePerTick);

            timestamp = Time.time + tick;
        }
    }
Ejemplo n.º 25
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.CompareTag("Player"))
     {
         Destroy(gameObject);
         Health.AddHealth(50);
         ReminderManager.HealthBoost();
     }
 }
Ejemplo n.º 26
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        Health targetHealth = collision.gameObject.GetComponent <Health>();

        if (targetHealth != null)
        {
            targetHealth.AddHealth(healAmount);
            Destroy(gameObject);
        }
    }
Ejemplo n.º 27
0
    public override void Use(GameObject target)
    {
        base.Use(target);

        Debug.Log("USING HEAL");
        Health health = target.GetComponent <Health>();
        int    heal   = (int)(health.maxHealth * 0.3f);

        health.AddHealth(heal);
    }
Ejemplo n.º 28
0
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.name.Contains("Bullet"))
     {
         ParticleSystem cParticle    = Instantiate(particle, transform.position, Quaternion.identity);
         Health         healthScript = GetComponent <Health>();
         healthScript.AddHealth(-1f);
         Destroy(other.gameObject);
     }
 }
Ejemplo n.º 29
0
    // Bei Kontakt mit PowerUp wird die entsprechende Funktion aufgerufen
    void OnTriggerEnter2D(Collider2D collider)
    {
        if (collider.gameObject.GetComponent <PowerUpObject>())
        {
            SoundManager.instance.PlayEffect(5);

            FireRate  powerUpFireRate  = collider.gameObject.GetComponent <FireRate>();
            Health    powerUpHealth    = collider.gameObject.GetComponent <Health>();
            Assistant powerUpAssistant = collider.gameObject.GetComponent <Assistant>();
            Points    powerUpPoints    = collider.gameObject.GetComponent <Points>();

#if UNITY_STANDALONE
            Speed powerUpSpeed = collider.gameObject.GetComponent <Speed>();

            if (powerUpSpeed)
            {
                powerUpSpeed.AddSpeed(pMovement);
                powerUpSpeed.gameObject.SetActive(false);
            }
#endif

            if (powerUpFireRate)
            {
                powerUpFireRate.AddFireRate(pWeapon);
                powerUpFireRate.AddFireRate(aWeapon);
                powerUpFireRate.AddFireRate(aWeapon2);
                powerUpFireRate.gameObject.SetActive(false);
            }
            else if (powerUpHealth)
            {
                powerUpHealth.AddHealth(pBHealth);
                powerUpHealth.gameObject.SetActive(false);
            }
            else if (powerUpPoints)
            {
                powerUpPoints.AddPoints();
                powerUpPoints.gameObject.SetActive(false);
            }
            else if (powerUpAssistant)
            {
                assistantCount = powerUpAssistant.AddAssistantCount(assistantCount);
                powerUpAssistant.gameObject.SetActive(false);

                if (assistantCount == 3)
                {
                    assistant.SetActive(true);
                }
                else if (assistantCount == 5)
                {
                    assistant2.SetActive(true);
                }
            }
        }
    }
Ejemplo n.º 30
0
    public int healAmount = 30; // Usually out of 100 (max health)

    void OnTriggerEnter2D(Collider2D collider)
    {
        Health health = collider.gameObject.GetComponent <Health>();
        bool   healed = health.AddHealth(healAmount);

        // Don't use up the medpac unless the player was actually healed (not at max health)
        if (healed)
        {
            Destroy(gameObject);
        }
    }