TakeDamage() public method

public TakeDamage ( float amount ) : void
amount float
return void
Example #1
0
    IEnumerator Attackpeudevie()
    {
        Anim.Play("Attack_02");
        // Reset the timer.
        timer = 0f;
        jouelaniamtiondattaque = true;
        yield return new WaitForSeconds(0.6f);
        timer = 0f;
        // Première partie de l'anim
        if (playerHealth.currentHealth > 0&&enemyHealth.currentHealth>0)
        {
            // ... damage the player.
            playerHealth = target.GetComponent<PlayerHealth>();
            playerHealth.TakeDamage(attackDamage/3);
        }
        yield return new WaitForSeconds(1.4f);
        timer = 0f;

        // Seconde partie de l'anim
        if (playerHealth.currentHealth > 0&&enemyHealth.currentHealth>0)
        {
            // ... damage the player.
            playerHealth = target.GetComponent<PlayerHealth>();
            playerHealth.TakeDamage(attackDamage / 3);
        }
        jouelaniamtiondattaque = false;
    }
Example #2
0
	void OnTriggerEnter(Collider other) {
		if (other.tag == "Player") {
			health = other.gameObject.GetComponent<PlayerHealth> (); 
			health.TakeDamage (30);
		}

		//Destroy(other.gameObject);
	}
Example #3
0
	void OnTriggerEnter2D(Collider2D other){
		if((other.gameObject.tag == "Player" && attacking == false))
		{
			playerHealth = other.gameObject.GetComponent<PlayerHealth>();
			playerHealth.TakeDamage(batonDamage);
			StartCoroutine(attack());
		}
		
	}
Example #4
0
    private void OnTriggerEnter(Collider other)
    {
        PlayerHealth player = other.GetComponent <PlayerHealth>();

        player?.TakeDamage(damageAmount);

        OnDie();
        Destroy(gameObject);
    }
Example #5
0
 private void Fight(PlayerHealth player)
 {
     player.TakeDamage(10);
     player.GetComponent<GridMovement>().Freeze();
     player.GetComponent<GridMovement>().Invoke("UnFreeze", 1);
     Destroy(gameObject, 1);
     movement.enabled = false;
     aggroCollider.gameObject.SetActive(false);
 }
Example #6
0
 void Attack()
 {
     //Debug.Log ("turn: " + turnController.playerTurn);
     if (turnController.playerTurn == 0) {
         turnController.BeginTurn();
         player = GameObject.FindGameObjectWithTag ("Player");
         playerHealth = player.GetComponent<PlayerHealth> ();
         if (playerHealth.currentHealth > 0) {
             playerHealth.TakeDamage (attackPoint);
         }
         turnController.EndTurn();
     }
 }
Example #7
0
    float timer; // Timer for counting up to the next attack.

    #endregion Fields

    #region Methods

    void Attack()
    {
        Anim.Play("Attack1h1");
        // Reset the timer.
        timer = 0f;
        playerHealth = target.GetComponent<PlayerHealth>();
        // If the player has health to lose...
        if (playerHealth.currentHealth > 0)
        {
            // ... damage the player.
            playerHealth.TakeDamage(attackDamage);
        }
    }
Example #8
0
	void OnTriggerEnter (Collider other)
	{
		trail.transform.SetParent(null);
		Destroy(trail, 5f);
		particles.SetActive (true);
		particles.transform.SetParent (null);
		this.gameObject.SetActive (false);
		if(other.gameObject.CompareTag("Player"))
		{
			playerHealth = other.gameObject.GetComponent<PlayerHealth>();
			playerHealth.TakeDamage (bulletDamage);
		}
	}
Example #9
0
    float timer; // Timer for counting up to the next attack.

    #endregion Fields

    #region Methods

    void Attack(GameObject target)
    {
        anim.SetTrigger("Attack");
        // Reset the timer.
        timer = 0f;
        playerHealth = target.GetComponent<PlayerHealth>();
        // If the player has health to lose...
        if (playerHealth.currentHealth > 0)
        {
            // ... damage the player.
            playerHealth.TakeDamage(attackDamage);
        }
    }
Example #10
0
    void OnTriggerEnter2D(Collider2D hitInfo)
    {
        PlayerHealth player = hitInfo.GetComponent <PlayerHealth>();

        if (player != null)
        {
            player.TakeDamage(damage);
        }

        //Instantiate(impactEffect, transform.position, transform.rotation);
        if (hitInfo.gameObject.tag == "Player")
        {
            Destroy(gameObject);
        }
    }
Example #11
0
    void OnTriggerEnter2D(Collider2D collision)
    {
        Player player = collision.GetComponent <Player>();

        if (player != null)
        {
            Debug.Log("hit player");
            PlayerHealth playerHealth = player.GetComponent <PlayerHealth>();
            if (playerHealth != null)
            {
                Debug.Log("shot player");
                playerHealth.TakeDamage(Damage);
            }
        }
    }
Example #12
0
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
            PlayerHealth playerHealth = other.GetComponent <PlayerHealth> ();
            playerHealth.TakeDamage(damage);
        }


        if (!other.gameObject.CompareTag("Enemy") && !other.gameObject.CompareTag("Spawn") && !other.gameObject.CompareTag("Aggro") && !other.gameObject.CompareTag("Spawn Point"))
        {
            print(other.tag);
            Destroy(this.gameObject);
        }
    }
Example #13
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        GameObject other = collision.gameObject;

        if (isBehindHomeField)
        {
            //take damage from attackers with damagers only
            if (other.GetComponent <Attacker>() && other.GetComponent <Damager>())
            {
                float damage = other.GetComponent <Damager>().GetDamage();
                playerHealth.TakeDamage(Mathf.RoundToInt(damage));
            }
        }
        Destroy(other);
    }
Example #14
0
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "PlayerCollider" && this.tag == "BadBarrel")
        {
            playerHealth.TakeDamage(20);
            pc.AddCoins(5);
            Destroy(gameObject);
        }

        if (other.tag == "PlayerCollider" && this.tag == "GoodBarrel")
        {
            pc.AddCoins(10);
            Destroy(gameObject);
        }
    }
Example #15
0
	void Update () {
		Collider[] hits = Physics.OverlapSphere (hitPoint.position, radius, playerLayer);

		foreach (Collider c in hits) {
			if (c.isTrigger) {
				continue;
			}
			collided = true;

			if (collided) {
				playerHealth.TakeDamage (damageCount);
			}

		}
	}
Example #16
0
 void Attack()
 {
     // If the player has health to lose...
     if (playerHealth.currentHealth > 0)
     {
         // ... damage the player.
         playerHealth.TakeDamage(attackDamage);
         behaviour.takeDamage(attackDamage);
         Debug.Log("Damaging from enemy");
     }
     else
     {
         //spawn.
     }
 }
Example #17
0
    public IEnumerator Death()
    {
        // Do visual/audio death stuff then wait to explode and depower.
        health = 0;
        custom.PlayClipAt(deathClip, theTransform.position);
        anim.SetTrigger("Death");
        yield return(new WaitForSeconds(0.35f));

        if (Functions.DeltaMax(playerPos.x, theTransform.position.x, 3.05f) && Functions.DeltaMax(playerPos.y, theTransform.position.y, 2f))
        {
            playerH.TakeDamage(20f, true, isRight);
        }
        GetComponentInChildren <Light>().enabled = false;
        DeathState();
    }
Example #18
0
 void Attack()
 {
     if (playerHealth.currentHealth > 0 && attackComplete())
     {
         timer            = 0f;
         zombieAudio.clip = attackClip;
         zombieAudio.Play();
         Vector3 direction = (new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z) - transform.position).normalized;
         Vector3 newDir    = Vector3.RotateTowards(transform.forward, direction, 2f, 0.0F);
         transform.rotation = Quaternion.LookRotation(newDir);
         feedback.color     = new Color(1, 0, 0, 2);
         feedback.text      = "Damage received: " + attackDamage.ToString();
         playerHealth.TakeDamage(attackDamage);
     }
 }
Example #19
0
    void Attack()
    {
        timer = 0f;

        if (playerHealth.HitPointsRemaining > 0)
        {
            playerHealth.TakeDamage(attackDamage, transform.position);

            if (flyingEnemy != null)
            {
                flyingEnemy.isAttacking  = false;
                flyingEnemy.isRetreating = true;
            }
        }
    }
Example #20
0
    public override void Attack()
    {
        anim.SetTrigger("attack");
        playerHealth.TakeDamage(damage);
        timeBtwAttacks = startTimeBtwAttacks;

        //ParticleSystem psInstance = Instantiate<ParticleSystem>(punchParticles);

        if (punchParticles != null)
        {
            GameObject obj = Instantiate(punchParticles, playerPosition.position, Quaternion.identity);

            Destroy(obj.gameObject, 0.75F);
        }
    }
Example #21
0
 private void OnCollisionEnter(Collision collision)
 {
     Instantiate(impact, projectileTargetPos); //instantiate particle effect
     particleTimer = 1f;                       //set countdown for particle object life span
     if (particleTimer <= 0f)
     {
         Destroy(impact);//destroy particle after 1 second
     }
     Destroy(gameObject);
     if (collision.gameObject.CompareTag("Player") && !playerHPScript.iSceneEnabled)
     {
         playerHPScript.iSceneEnabled = true;
         playerHPScript.TakeDamage(goblin.goblinDamage);
     }
 }
    void Attack()
    {
        // Reset the timer.
        timer = 0f;

        // If the player has health to lose...
        if (playerHealth.currentHealth > 0)
        {
            // ... damage the player.
            playerHealth.TakeDamage(attackDamage);

            enemyAudio.clip = attackSound;
            enemyAudio.Play();
        }
    }
Example #23
0
 public void AttackPlayerPositions(List <Vector2Int> positions, int damage)
 {
     for (int index = 0; index < positions.Count; index++)
     {
         GameObject type = grid[positions[index].x, positions[index].y];
         if (type != null)
         {
             PlayerMovement player = type.GetComponent <PlayerMovement>();
             if (player)
             {
                 playerHealth.TakeDamage(damage);
             }
         }
     }
 }
    ////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////

    // On collision with a trigger collider...
    void OnTriggerEnter2D(Collider2D other)
    {
        // Check the tag of the object the player
        // has collided with
        if (other.tag == "Player")
        {
            //////annimationstop
            animate.SetBool("Attack", true);

            playerHealth.TakeDamage(30);

            this.GetComponent <CircleCollider2D>();
            collider.enabled = false;
        }
    }
Example #25
0
 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.CompareTag("N") ||
         other.gameObject.CompareTag("S") ||
         other.gameObject.CompareTag("W") ||
         other.gameObject.CompareTag("E"))
     {
         Destroy(gameObject);
     }
     else if (other.CompareTag("Player"))
     {
         playerHealth.TakeDamage(dameg);
         Destroy(gameObject);
     }
 }
Example #26
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject == player)
        {
            PlayerHealth playerHealth = player.GetComponent <PlayerHealth>();

            // If the player has health to lose...
            if (playerHealth.currentHealth > 0)
            {
                playerHealth.TakeDamage(damage);
            }
        }

        Destroy(gameObject, 0.5f);
    }
Example #27
0
 void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Player")
     {
         Instantiate(cannonShellExplosion, transform.position, Quaternion.identity);
         Destroy(gameObject);
         playerHealth = other.gameObject.GetComponent <PlayerHealth>();
         playerHealth.TakeDamage(30);
     }
     else if (other.tag == "Ground")
     {
         Instantiate(cannonShellExplosion, transform.position, Quaternion.identity);
         Destroy(gameObject);
     }
 }
Example #28
0
 private void OnTriggerEnter2D(Collider2D col)
 {
     if (col.gameObject.CompareTag("WaterCollider"))
     {
         playerIsSlowed = true;
     }
     if (col.gameObject.CompareTag("EnemyCollider"))
     {
         health.TakeDamage(10.0f);
     }
     if (col.gameObject.CompareTag("CoinCollider"))
     {
         Destroy(col.gameObject);
     }
 }
Example #29
0
 void OnTriggerEnter2D(Collider2D coll)
 {
     if (coll.gameObject.tag == "Player")
     {
         playerhealth.TakeDamage(30);
         Destroy(gameObject);
     }
     else if (coll.gameObject.tag == "Thrower")
     {
     }
     else if (coll)
     {
         Destroy(gameObject);
     }
 }
Example #30
0
 void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.tag == "Player")
     {
         playerHP.TakeDamage();
         rotating = true;
         jump     = true;
         StandardFireFunctions.FireDegreeOffsetFromPlayer(hatcher, 180);
         StartCoroutine(Timer());
     }
     if (collision.gameObject.layer == 10 && rotating)   // Layer 10 == Ground
     {
         rotationVector = new Vector3(0, 0, -rotationVector.z);
     }
 }
 void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Player"))
     {
         PlayerHealth playerhealth = other.GetComponent <PlayerHealth> ();
         playerhealth.TakeDamage(10f);
         Destroy(gameObject);
     }
     if (other.CompareTag("Enemy"))
     {
         EnemyHealth enemyhealth = other.GetComponent <EnemyHealth> ();
         enemyhealth.TakeDamage(50f);
         Destroy(gameObject);
     }
 }
Example #32
0
 void OnTriggerEnter(Collider other)
 {
     if (other.tag.Equals("Player") && !activated)
     {
         activated = true;
         audioPlayer.Play();
         MeshFilter trapMesh = gameObject.GetComponentInChildren <MeshFilter>();
         trapMesh.mesh = trapClosed;
         PlayerHealth playerHealth = other.GetComponent <PlayerHealth>();
         playerHealth.TakeDamage(damage);
         PlayerMovement playerMovement = other.GetComponent <PlayerMovement>();
         playerMovement.ApplyMovementEffect(new MovementEffect(lengthOfSnare, 0.0f));
         Destroy(gameObject, lengthOfSnare);
     }
 }
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.tag == "InnerBorder")
     {
         playerHealth.DestroyShip();
     }
     else if (collision.gameObject.tag == "EnemyCollider")
     {
         playerHealth.TakeDamage();
     }
     else if (collision.gameObject.tag == "Collectable")
     {
         collectionController.Collect(collision.gameObject);
     }
 }
Example #34
0
    private void OnTriggerEnter(Collider other)
    {
        ///If the colliding object is the Player and they are not invincible this function will set the players velocity to 0
        ///and the potion launch variable to true so they player can get properly knocked back/up when the add force is called.
        ///When the player triggers/(collides with) the orc the iSceneEnabled becomes true and applys damage to the player.
        ///This is needed so the player is not constantly dealt damage before the invincibility
        if (other.CompareTag("Player") && !playerHPScript.iSceneEnabled)
        {
            other.attachedRigidbody.velocity = Vector3.zero;
            player.potionLaunch = true;

            orcPosition          = transform.position;
            orcKnockBackVelocity = new Vector3((other.attachedRigidbody.transform.position.x) - orcPosition.x, (other.attachedRigidbody.transform.position.y + potionLaunchEffectHeight) - orcPosition.y, 0);

            //normalise vector
            magnitude = AirPotion.GetMag(orcKnockBackVelocity.x, orcKnockBackVelocity.y);
            orcKnockBackVelocity.x /= magnitude;
            orcKnockBackVelocity.y /= magnitude;

            //apply explosion force
            orcKnockBackVelocity *= knockBackForce;
            //zero velocity then add force to rigid body

            other.attachedRigidbody.AddForce(orcKnockBackVelocity, ForceMode.Impulse);

            playerHPScript.iSceneEnabled = true;

            if (!orcPatrolParent.dealDamage)
            {
                playerHPScript.TakeDamage(orc.orcDamage);
                orcPatrolParent.dealDamage = true;
            }
        }
        else if (other.CompareTag("Potion"))
        {
            moveThrough = true;
            anim.SetTrigger("stun");
        }
        else
        {
            ///If the Orc is colliding with anything other then the Player and Potion,
            ///then it will turn around.
            if (!other.CompareTag("Player") && !other.CompareTag("Potion"))
            {
                orcPatrolParent.movingRight = !orcPatrolParent.movingRight;
            }
        }
    }
Example #35
0
    public void OnReveal(Tile tile, bool playerClicked)
    {
        if (playerClicked)
        {
            if (tile.IsOccupied && _revealCount > 0)
            {
                Enemy enemy = tile.Occupant;
                enemy.OnReveal(true);

                int levelDiff = Mathf.Max(0, enemy.Level - Level);
                int damage    = CalculateDamage(levelDiff);
                Health.TakeDamage(damage);

                if (Health.CurrentHealth > 0)
                {
                    int exp = CalculateExpFromKill(enemy.Level);
                    AddExp(exp);
                }
            }
            else
            {
                if (tile.IsOccupied)
                {
                    Destroy(tile.Occupant.gameObject);
                    tile.Occupant = null;
                }
                RecursiveRevealEmptyTile(tile, true);
            }
        }
        else
        {
            Enemy enemy = tile.Occupant;
            if (enemy != null)
            {
                enemy.OnReveal(playerClicked);
            }
            int nearby = GetNearby(tile);
            if (nearby != 0)
            {
                tile.SetNearbyCount(nearby);
            }
        }
        _revealCount++;
        if (_revealCount == Board.Instance.GetTiles().Length)
        {
            Messenger.SendMessage(Message.AllTilesRevealed);
        }
    }
    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        enemy  = null;

        if (Input.GetMouseButtonDown(1) && timer >= timeBetweenSwings && Time.timeScale != 0)
        {
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100))
            {
                if (hit.transform.CompareTag("Enemy"))
                {
                    controller = hit.transform.gameObject;
                    var distance = Vector3.Distance(controller.transform.position, player.transform.position);

                    EnemyHealth enemyHealth = controller.GetComponent <EnemyHealth>();
                    if (enemyHealth != null /*&&distance <= 4*/)
                    {
                        // ... the enemy should take damage.
                        enemyHealth.TakeDamage(50 + strength);
                    }
                    if (enemyHealth.currentHealth <= 0)
                    {
                        strength += 10;
                        regen.TakeDamage(-30);
                    }
                    //    targetscript.damager(dmggiven * times.deltaTime);
                }
                else
                {
                    enemy = null;
                }
            }

            /*if ((Physics.Raycast(controller.transform.position, hit, 100)
             *      //Physics.SphereCast(controller.transform.position,4, controller.transform.forward, out hit, 3)
             * ))
             * {
             *  EnemyHealth enemyHealth = hit.collider.GetComponent<EnemyHealth>();
             *  if (enemyHealth != null)
             *  {
             *      // ... the enemy should take damage.
             *      enemyHealth.TakeDamage(50);
             *  }
             *
             * }*/
            Swing();
        }
    }
Example #37
0
    void Fire()
    {
        // Reset the timer.
        timer = 0f;

        // Set the shootRay so that it starts at the end of the gun and points forward from the barrel.
        //shootRay.origin = transform.position;
        shootRay.origin    = camera.transform.position;     //fwd from camera
        shootRay.direction = transform.forward;

        // Perform the raycast against gameobjects on the shootable layer and if it hits something...
        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            // Try and find an EnemyHealth script on the gameobject hit.
            //EnemyHealth enemyHealth = shootHit.collider.GetComponent<EnemyHealth>();
            TargetDummy targetDummy = shootHit.collider.GetComponent <TargetDummy>();

            // If the EnemyHealth component exist...
            if (targetDummy != null)
            {
                knockback = transform.forward * knockbackForce;

                // ... the enemy should take damage.
                targetDummy.TakeDamage(damagePerShot, knockback);
                PlayHitSounds();
            }

            //
            PlayerHealth playerHealth = shootHit.collider.GetComponent <PlayerHealth>();             //CLEAN UP LATER
            if (playerHealth != null)
            {
                knockback = transform.forward * knockbackForce;

                // ... the enemy should take damage.
                playerHealth.TakeDamage(damagePerShot, knockback);
                PlayHitSounds();
            }
            //

            // Impact effect
            Impact();
        }
        // If the raycast didn't hit anything on the shootable layer...
        else
        {
            // Endpoint = camera.fwd + max distance
        }
    }
 void OnTriggerEnter(Collider target)
 {
     if (target.CompareTag("ammo"))
     {
         //   myAudioSource.PlayOneShot(ammoPickUp);
         AudioSource.PlayClipAtPoint(ammoPickUp, transform.position);
         addAmmo();
         Destroy(target.gameObject);
     }
     if (target.CompareTag("health"))
     {
         AudioSource.PlayClipAtPoint(healthPickUp, transform.position);
         playerhealth.TakeDamage(-30);
         Destroy(target.gameObject);
     }
 }
Example #39
0
    float timer; // Timer for counting up to the next attack.

    #endregion Fields

    #region Methods

    IEnumerator Attackforte()
    {
        Anim.Play("Attack_01");
        // Reset the timer.
        timer = 0f;
        jouelaniamtiondattaque = true;
        yield return new WaitForSeconds(1f);
        timer = 0f;
        jouelaniamtiondattaque = false;

        // If the player has health to lose...
        if (playerHealth.currentHealth > 0&&enemyHealth.currentHealth>0)
        {
            playerHealth = target.GetComponent<PlayerHealth>();
            // ... damage the player.
            playerHealth.TakeDamage(attackDamage);
        }
    }
Example #40
0
    float timerforspawn; // Timer entre l'invocation de monstres

    #endregion Fields

    #region Methods

    IEnumerator Attacksimple(GameObject target)
    {
        Anim.Play("DemPunch");
        // Reset the timer.
        timer = 0f;
        jouelaniamtiondattaque = true;
        yield return new WaitForSeconds(0.7f);
        timer = 0f;
        // Première partie de l'anim
        playerHealth = target.GetComponent<PlayerHealth>();
        if (playerHealth.currentHealth > 0 && enemyHealth.currentHealth > 0)
        {
            // ... damage the player.
            playerHealth.TakeDamage(attackDamage);
        }
        yield return new WaitForSeconds(0.3f);
        timer = 0f;
        jouelaniamtiondattaque = false;
    }