public virtual void     TakeDamage(int damage)
    {
        if (currentHp > 0)
        {
            currentHp -= damage;
        }
        else
        {
            return;
        }

        if (currentHp <= 0)
        {
            _deathScript.Die();
            if (soundSource != null)
            {
                soundSource.clip = death;
                soundSource.Play();
            }
            return;
        }
        if (soundSource != null)
        {
            soundSource.clip = hurt;
            soundSource.Play();
        }
    }
Ejemplo n.º 2
0
 void Update()
 {
     if (Physics2D.Linecast(startingPoint, endPoint, layer))
     {
         death.Die();
     }
 }
 // Update is called once per frame
 protected void Update()
 {
     // FAIL SALE FOR FALLING OFF THE WORLD
     if (photonView.IsMine && transform.position.y < minY)
     {
         death?.Die();
     }
 }
Ejemplo n.º 4
0
    public void Die()
    {
        Death death = GetComponent <Death>();

        if (death != null)
        {
            death.Die();
        }
    }
 public void setHealth(double damageRecieved)         //this is how the enemy takes damage
 {
     this.health = health - damageRecieved;
     audioManager.GetComponent <AudioManager> ().PlaySound(bloodSplatterSound);
     bloodSpatter.Play();
     if (this.health <= 0)
     {
         dead.Die();
     }
 }
Ejemplo n.º 6
0
//	void OnTriggerEnter(Collider coll) {
//		Bullet bullet = coll.GetComponent<Bullet>();
//
//		if (bullet) {
//			// if the shield is raised, the bullets shouldn't hit the body directly at all,
//			// but this will double check that to make sure only the shield handles the damage
//			if (!shield.isRaised) Damage(bullet.damage);
//		}
//	}

    public void Damage(float damageAmount)
    {
        hp = Mathf.Max(0, hp - damageAmount);
        if (hp <= 0)
        {
            if (!death.isDead)
            {
                death.Die();
            }
        }
    }
Ejemplo n.º 7
0
    private void Hit()
    {
        if (currentDeathComponent == null)
        {
            return;
        }

        if (Input.GetMouseButton(0))
        {
            meleeAudioSource.Play();
        }
        currentDeathComponent.Die();
    }
Ejemplo n.º 8
0
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.CompareTag("Projectile"))
        {
            death.Die();
        }

        if (col.CompareTag("Shield"))
        {
            if (!spooked && spookTimeout <= 0)
            {
                bearing = transform.position - col.gameObject.transform.position;
                Spook(bearing);
            }
        }
    }
Ejemplo n.º 9
0
    /// <summary>
    /// TakeDamage
    /// used to deal damage to the enemy. function is called by the damage dealing source
    /// </summary>
    /// <param name="amount">The amount of damage dealt to the enemy</param>
    public void TakeDamage(int amount)
    {
        if (isDead)
        {
            // if the enemy is dead, don't deal damage, just return
            return;
        }

        // subtract the damage from the current health
        currentHealth -= amount;

        if (currentHealth <= 0 && !isDead)
        {
            isDead = true;
            // if the current health is 0 or less, call the death function
            if (death != null)
            {
                death.Die();
            }
        }
    }
 /**
  * Should always handle destroying the object
  * Prevents the object from being destroyed if it could be respawned
  */
 private void destroy()
 {
     death?.Die();
 }
Ejemplo n.º 11
0
 public void Kill()
 {
     playerDeath.Die();
 }
Ejemplo n.º 12
0
    void Update()
    {
        //print("run " + moveAllow + " shoot " + shootAllow + " mele " + meleeAllow);
        if (HP <= 0)
        {
            DEATH.Die();
        }
        else
        {
            if (moveAllow && !shootAllow && !meleeAllow)
            {
                try
                {
                    //   print(gameObject.name + "i run");
                    MOVE.Turn(Dot);
                    MOVE.Run(DirectionToPlayer);
                }
                catch
                {
                    print(gameObject.name + ": i cant move");
                }
            }
            else if (shootAllow && !meleeAllow && !moveAllow)
            {
                //  print("i shoot");
                try
                {
                    MOVE.Turn(Dot);
                    SHOOT.Shoot(DirectionToPlayer);
                }
                catch
                {
                    // print(gameObject.name + ": i cant shoot");
                    MOVE.Run(DirectionToPlayer);
                }
            }
            else if (meleeAllow)
            {
                MOVE.Turn(Dot);
                try
                {
                    //  print(gameObject.name + "i melee");
                    MELEE.Atack();
                }
                catch
                {
                    // print(gameObject.name + ": i cant melee");
                    MOVE.Stay();
                }
            }
            else
            {
                try
                {
                    // print(gameObject.name + "i stay");

                    MOVE.Stay();
                }
                catch
                {
                    // print(gameObject.name + ": i cant move");
                }
            }
        }
    }