Exemple #1
0
    public void TakeDamage(GameObject attacker, float damage, float force = 0, Vector3 impactDirection = new Vector3())
    {
        playSound(sndHit);

        // impactDirection.y += 0.5f;
        if (attacker.Equals(gameObject))
        {
            return;
        }

        legs.addImpact(impactDirection.normalized, force);
        if (canTakeDamage)
        {
            // Instantiate the particle effect upon hit.
            particleObject = Instantiate(deathEffect);
            particleObject.transform.position = transform.position;
            particleObject.transform.rotation = Quaternion.LookRotation(impactDirection.normalized);

            // code for health / player dying
            this.health -= damage;
            playerStats.showHealth(gameObject, playerID);       // Shows the player health bar when he gets hit./
            GameManager.instance.scoreCounter.updateScore(attacker.GetComponent <MasterBody>().playerID, "hurt", (int)Mathf.Ceil(damage));
            if (this.health <= 0)
            {
                Debug.Log("health decreased.");
                GameManager.instance.scoreCounter.updateScore(attacker.GetComponent <MasterBody>().playerID, "kill");
                PlayerDies();
            }
        }
    }