コード例 #1
0
    public void TakeDamage(int damage, Player opponent)
    {
        if (!isShielded && !isInvincible)
        {
            opponent.score += 10;
            healthSystem.Damage(damage);
            movementSpeed   = movementSpeed * 1.05f;
            projectileSpeed = projectileSpeed * 1.1f;
            if (healthSystem.GetHealth() == 0 && player.GetStocks() == 1)
            {
                StocksLeftText.text = "0";
                Die();
            }
            else if (healthSystem.GetHealth() == 0)
            {
                //stocks -= 1;
                player.SetStocks(player.GetStocks() - 1);
                StocksLeftText.text = player.GetStocks().ToString();
                StartCoroutine(Invicible());
                healthSystem    = new HealthSystem(100);
                movementSpeed   = baseMovementSpeed;
                projectileSpeed = baseProjectileSpeed;
                var healthbar = transform.Find("healthbar 1(Clone)");
                healthbar.Find("Bar").localScale = new Vector3(healthSystem.GetHealthPercent(), 1);
                HealthBar healthBar = healthbar.GetComponent <HealthBar>();

                healthBar.Setup(healthSystem);
            }
        }
    }
コード例 #2
0
ファイル: PlayerHealth.cs プロジェクト: 6d6f6d6f/collegeRL
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("BadGuy") && canBeHit)
        {
            myHealth.Damage(1);
            playerHealthDisplay.text = "HP: " + myHealth.GetHealth().ToString();

            if (myHealth.GetHealth() <= 0)
            {
                Destroy(gameObject);
                gameManager.LoseGame();
            }
            Debug.Log("Player Hit");
            playerMove.KnockBack(collision.gameObject);

            canBeHit    = false;
            immuneTimer = 1;
        }

        if (collision.gameObject.CompareTag("BadThing") && canBeHit)
        {
            myHealth.Damage(1);
            playerHealthDisplay.text = "HP: " + myHealth.GetHealth().ToString();

            if (myHealth.GetHealth() <= 0)
            {
                Destroy(gameObject);
                gameManager.LoseGame();
            }
            canBeHit    = false;
            immuneTimer = 1;
        }
    }
コード例 #3
0
    private void OnTriggerEnter(Collider collision)
    {
        enemy = collision.gameObject;
        HealthSystem healthSystem = enemy.GetComponent <HealthSystem>();

        if (enemy.CompareTag("Enemy"))
        {
            Instantiate(hitParticle);
            hitParticle.transform.position = particleSpawnPoint.position;
            switch (anim.GetInteger("comboCount"))
            {
            case 0:
                healthSystem.Damage(firstComboDamage);
                break;

            case 2:
                healthSystem.Damage(secondComboDamage);
                break;

            case 3:
                healthSystem.Damage(thirdComboDamage);
                break;
            }
        }
    }
コード例 #4
0
    private void OnCollisionEnter2D(Collision2D other)
    {
        HealthSystem enemy = other.gameObject.GetComponent <HealthSystem>();

        if (enemy)
        {
            if (!IsNotGettingDamage(other.gameObject))
            {
                if (enemy.tag == ("EnemyCriticalArea"))
                {
                    enemy.Damage(m_CriticalDamage);
                }
                else
                {
                    enemy.Damage(m_WeaponDamage);
                }
            }
        }

        EnemyProjectiles projectile = other.gameObject.GetComponent <EnemyProjectiles>();

        if (projectile)
        {
            projectile.Blocked();
            if (m_BlockAction)
            {
                m_BlockAction.ObjectBlocked();
            }
        }
    }
コード例 #5
0
    public void wasHit(string name)
    {
        if (name.Equals("treant"))
        {
            //health -= 1;
            //Debug.Log(health);
            healthSystem.Damage(20);
            healthBar.value = healthSystem.GetHealthInPercent();
        }
        else if (name.Equals("pitfall"))
        {
            healthSystem.Damage(20);
            healthBar.value = healthSystem.GetHealthInPercent();
        }
        else if (name.Equals("wolf"))
        {
            healthSystem.Damage(10);
            healthBar.value = healthSystem.GetHealthInPercent();
        }

        if (!playerAnim.GetCurrentAnimatorStateInfo(0).IsName("damaged"))
        {
            this.playerAnim.SetTrigger(damage);
        }
    }
コード例 #6
0
 private void OnTriggerEnter2D(Collider2D collider)
 {
     if (collider.tag == "Sword")
     {
         PlayerStats playerstats = player.GetComponent <PlayerStats>();
         HealthSystem.Damage(playerstats.Strength.Value);
     }
 }
コード例 #7
0
 protected virtual void OnTriggerEnter2D(Collider2D collider)
 {
     if (collider.CompareTag("Traps"))
     {
         isHit = true;
         healthSystem.Damage(10);
     }
 }
コード例 #8
0
    void FixedUpdate()
    {
        Vector3 localOffset    = new Vector3(explosionArea.offset.x, explosionArea.offset.y, 0f);
        float   localRadius    = explosionArea.radius;
        Vector3 localRadiusVec = new Vector3(localRadius, 0f, 0f);

        Vector3 globalOffset = transform.TransformVector(localOffset);
        float   globalRadius = transform.TransformVector(localRadiusVec).x;

        Vector3 explosionCenter = transform.position + globalOffset;


        Collider2D[] hitColliders =
            Physics2D.OverlapCircleAll(explosionCenter, globalRadius, layerMask);
        if (hitColliders.Length != 0)
        {
            // we actually hit something here
            foreach (Collider2D coll in hitColliders)
            {
                Transform target = coll.transform;
                // if the target has a dynamic rigidbody
                if (HasVisionBlock(target))
                {
                    continue;
                }

                Rigidbody2D body = coll.transform.GetComponent <Rigidbody2D> ();
                if (body && body.bodyType == RigidbodyType2D.Dynamic)
                {
                    Vector3 forceDir = (target.position - explosionCenter).normalized;
                    body.AddForce(forceDir * magnitude * Time.fixedDeltaTime, ForceMode2D.Impulse);
                }

                ObjectIdentity oi = target.GetComponent <ObjectIdentity> ();
                if (oi)
                {
                    float damage;
                    if (DamageOtherDict.TryGetValue(oi.objType, out damage))
                    {
//						Debug.Log (oi);
//						Debug.Log (damage);
                        HealthSystem hs = coll.transform.GetComponent <HealthSystem> ();
                        if (hs)
                        {
                            if (hs.hasImmunuePeriod)
                            {
                                hs.Damage(damage);
                            }
                            else
                            {
                                hs.Damage(damage * 60f * Time.fixedDeltaTime);
                            }
                        }
                    }
                }
            }
        }
    }
コード例 #9
0
 private void OnCollisionEnter2D(Collision2D other)
 {
     if (other.gameObject.CompareTag("SpikyEnemy"))
     {
         HealthSystem.Damage();
         healthBar.slider.value = HealthSystem.Health;
         potionBar.slider.value = HealthSystem.Shield;
     }
 }
コード例 #10
0
    //public Transform pfHealthBar;

    // Use this for initialization
    void Start()
    {
        //Transform healthBarTransform = Instantiate(pfHealthBar, new Vector3(0, 10), Quaternion.identity);
        //HealthBar healthBar = healthBarTransform.GetComponent<HealthBar>();
        healthBar.Setup(healthSystem);


        healthSystem.Damage(50);
    }
コード例 #11
0
    public virtual void Hurt(int damage, Vector2 dir)
    {
        if (!health.isDead)
        {
            if (isBloody)
            {
                BloodSystem.instance.Spill((Vector2)transform.position, dir);
            }

            health.Damage(damage);
        }
    }
コード例 #12
0
 public void FireDamage()
 {
     if (fireBurstIndex == 0)
     {
         fireDamage = 21;
     }
     else if (fireBurstIndex > 0)
     {
         fireDamage = 8;
     }
     fireBurstIndex++;
     healthSystem.Damage(fireDamage);
     StartCoroutine(FireDamageFeedback());
 }
コード例 #13
0
ファイル: Enemy_G.cs プロジェクト: nizap/IGD2021
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Boundary" || other.tag == "Obstacle" || other.tag == "Enemy")
        {
            return;
        }

        if (other.GetComponent <Attack>() != null)
        {
            HealthSystem.Damage(other.GetComponent <Attack>().Damage);
            if (other.tag == "Bullet")
            {
                if (other.GetComponent <CollisionExplosion>() != null)
                {
                    Instantiate(other.GetComponent <CollisionExplosion>().Explosion, other.transform.position, other.transform.rotation);
                }

                Destroy(other.gameObject);
            }
        }
        //on death
        if (Explosion != null && HealthSystem.GetHealth() == 0)
        {
            Instantiate(Explosion, transform.position, transform.rotation);
            if (Random.Range(0f, 1f) <= DropChance)
            {
                DropPowerUp();
            }
            EventSystemListeners.main.RemoveListener(gameObject);
            Destroy(gameObject);
        }
    }
コード例 #14
0
    public void TakeDamage(float damage)
    {
        if (_isRespawn)
        {
            return;
        }

        _healthSystem.Damage(damage);
        _healthBar.SetBarVisible(true);
        _audioSource.clip = _playerData.AudiosClips[0];
        _audioSource.Play();
        // --- When Player is dead
        if (_healthSystem.Health < 0.1f)
        {
            _audioSource.clip = _playerData.AudiosClips[1];
            _audioSource.Play();
            Item item = GetItem;
            if (item)
            {
                item.DestroyAfterUse();
            }

            StartCoroutine(Respawn());
        }
        // Stop health Regeneration when receive any damage
        if (_coroutineRegen != null)
        {
            _delayTimeToRegen = 0.0f;
            StopCoroutine(_coroutineRegen);
            _coroutineRegen = null;
        }
    }
コード例 #15
0
        public void Damaging_Zero_HPStaysSame()
        {
            HealthSystem hs = CreateHealthSystem();

            hs.Damage(0);
            Assert.AreEqual(_DEFAULT_MAX_HP, hs.CurrentHealth);
        }
コード例 #16
0
        public void CurrentHP_CannotBeBelow_Zero()
        {
            HealthSystem hs = CreateHealthSystem(_DEFAULT_MAX_HP, _DEFAULT_DMG_OR_HEAL);

            hs.Damage(_DEFAULT_MAX_HP);
            Assert.AreEqual(0, hs.CurrentHealth);
        }
コード例 #17
0
        public void Damaging_MoreThanZero_DecreasesHP()
        {
            HealthSystem hs = CreateHealthSystem();

            hs.Damage(_DEFAULT_DMG_OR_HEAL);
            Assert.AreEqual(_DEFAULT_MAX_HP - _DEFAULT_DMG_OR_HEAL, hs.CurrentHealth);
        }
コード例 #18
0
    private void AttackWithAdditionalDamage(UnitCombatSystem unitCombatSystem)
    {
        var attackedUnitStats = unitCombatSystem.GetUnitStats();
        var attackedUnitName  = attackedUnitStats.unitName;

        var attackedCounter = attackedUnitStats.counterType;

        if (attackedUnitStats.ability == AbilitiesEnum.Counter)
        {
            if (attackedCounter == unitStats.unitType)
            {
                _healthSystem.Damage(attackedUnitStats.counterDamage);
            }
        }
        foreach (var attackingTag in unitStats.attackTags)
        {
            if (attackingTag.tagName != attackedUnitName)
            {
                return;
            }
            unitCombatSystem._healthSystem.Damage(unitStats.damage + attackingTag.tagDamage);
            Debug.Log(
                $"Attack unit {unitCombatSystem.name}, normal damage: {unitStats.damage}, tag damage: {attackingTag.tagDamage}, overall dmg: {unitStats.damage + attackingTag.tagDamage}");
            return;
        }
    }
コード例 #19
0
ファイル: MeleeAttack.cs プロジェクト: brandonLaing/Mobile
    public override void Attack(Vector2 position)
    {
        Debug.Log($"Attempting attack\nPos: {position}\nRange: {range}\nDirection: {(position - (Vector2)transform.position).normalized}");


        Vector2 attackPoint = (position - (Vector2)transform.position).normalized * range;

        Collider2D[] foundObjects = Physics2D.OverlapCircleAll((Vector2)transform.position + attackPoint, areaOfEffect);

        attacks.Add((Vector2)transform.position + attackPoint, areaOfEffect);
        Debug.Log("Length " + foundObjects.Length);

        for (int i = 0; i < foundObjects.Length; i++)
        {
            Debug.Log("Transform: " + foundObjects[i].name);
            for (Transform trans = foundObjects[i].transform; trans != null; trans = trans.parent)
            {
                Debug.Log("Phase 2: " + foundObjects[i].name);
                HealthSystem hs = foundObjects[i].GetComponent <HealthSystem>();
                if (hs != null && hs.transform != this.transform)
                {
                    Debug.Log("Hit something");
                    hs.Damage(damage);
                }
            }
        }
    }
コード例 #20
0
 void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.tag == "Enemy")
     {
         healthSystem.Damage(10);
     }
 }
コード例 #21
0
ファイル: EnemyHandler.cs プロジェクト: yabejarano10/techTest
 void OnCollisionStay2D(Collision2D collision)
 {
     if (collision.gameObject.tag == "Player" && Input.GetKeyUp("f"))
     {
         healthSystem.Damage(10);
     }
 }
コード例 #22
0
ファイル: Player.cs プロジェクト: NovemberMeme/Dreaming-Deeps
        public void Damage(Enemy attacker, float damageMultiplier)
        {
            Vector3 attackerPosition = GetPosition();

            if (attacker != null)
            {
                attackerPosition = attacker.GetPosition();
            }

            int damageAmount = Mathf.RoundToInt(8 * damageMultiplier * UnityEngine.Random.Range(.8f, 1.2f));

            bool isInvulnerable = Time.time < invulnerableTime;

            if (!isInvulnerable)
            {
                healthSystem.Damage(damageAmount);
                DamagePopup.Create(GetPosition(), damageAmount, true);
            }

            Sound_Manager.PlaySound(Sound_Manager.Sound.Player_Hit, GetPosition());

            Vector3 bloodDir = (GetPosition() - attackerPosition).normalized;

            BloodParticleSystemHandler.Instance.SpawnBlood(5, GetPosition(), bloodDir);
        }
コード例 #23
0
ファイル: Enemy.cs プロジェクト: Delgadox/diplom_project
    public void Damage(IEnemyTargetable attacker)
    {
        Vector3 bloodDir = (GetPosition() - attacker.GetPosition()).normalized;

        Blood_Handler.SpawnBlood(GetPosition(), bloodDir);

        int damageAmount = 30;

        DamagePopup.Create(GetPosition(), damageAmount, false);
        healthSystem.Damage(damageAmount);
        if (IsDead())
        {
            FlyingBody.Create(GameAssets.i.pfEnemyFlyingBody, GetPosition(), bloodDir);
            Destroy(gameObject);
        }
        else
        {
            // Knockback
            transform.position += bloodDir * 5f;
            if (hitUnitAnim != null)
            {
                state = State.Busy;
                characterBase.PlayHitAnimation(bloodDir * (Vector2.one * -1f), SetStateNormal);
            }
        }
    }
コード例 #24
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.CompareTag("Player"))
     {
         hSystem.Damage(20);
     }
 }
コード例 #25
0
ファイル: Buildings.cs プロジェクト: PREMINDA/BuildGame
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.V))
     {
         healthSystem.Damage(10);
     }
 }
コード例 #26
0
    // Checks with player is doing damage and minus the damage done from the other players health
    public void Damage(CharacterBattle attacker, int damageAmount)
    {
        healthSystem.Damage(damageAmount);
        // CodeMonkey.CMDebug.TextPopup("health " + healthSystem.GetHealthAmount(), GetPosition());
        Vector3 dirFromAttacker = (GetPosition() - attacker.GetPosition()).normalized;

        if (isPlayerTeam)
        {
            GameObject.FindGameObjectWithTag("P1Life").GetComponent <Health>().health -= damageAmount;
        }
        else
        {
            GameObject.FindGameObjectWithTag("P2Life").GetComponent <Health>().health -= damageAmount;
        }
        DamagePopup.Create(GetPosition(), damageAmount, false);
        characterBase.SetColorTint(new Color(1, 0, 0, 1f));
        Blood_Handler.SpawnBlood(GetPosition(), dirFromAttacker);


        if (healthSystem.IsDead())
        {
            // Died
            Debug.Log("level" + " " + level + " " + "complete");
        }
    }
コード例 #27
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.tag == "Bullet" || col.name == "Bullet(Clone)")
     {
         playerHealtShystem.Damage(1f);
     }
 }
コード例 #28
0
        public void Damage_Positive_ReducesHealth()
        {
            HealthSystem hs = CreateDefaultHealthSystem();

            hs.Damage(_DEFAULT_DAMAGE_AND_HEALING);
            Assert.AreEqual(_DEFAULT_START_HP - _DEFAULT_DAMAGE_AND_HEALING, hs.CurrentHitPoints);
        }
コード例 #29
0
        protected override void OnCollisionEnter(Collision hit)
        {
            //we don't want to do the base trigger enter
            HealthSystem health = hit.gameObject.GetComponent <HealthSystem>();

            //if we hit something with health we want to hurt it and destroy the projectile
            if (health != null)
            {
                health.Damage(this._damage);
            }

            if (hit.collider.tag != GlobalUtilities.LOCAL_PLAYER_TAG)
            {
                this._isProjecting = false;
                if (hit.collider.CompareTag(GlobalUtilities.ENEMY_TAG))
                {
                    HandleHit(hit, hit.contacts [0].point);
                }
                else
                {
                    this._handleStop            = true;
                    this._landingSpot           = hit;
                    this._rigidBody.drag        = 0;
                    this._rigidBody.angularDrag = 1;
                }
            }
        }
コード例 #30
0
        public void Damage_Negative_ThrowsAssertException()
        {
            HealthSystem hs             = CreateDefaultHealthSystem();
            const int    negativeDamage = -10;

            Assert.Throws <NegativeInputException>(() => hs.Damage(negativeDamage));
        }