Beispiel #1
0
 public static void OnDamagePlayer(float amount)
 {
     if (PlayerDamaged != null)
     {
         PlayerDamaged.Invoke(amount);
     }
 }
    /// <summary>
    /// Damage the Player, if not invunverable
    /// </summary>
    /// <param name="damage">Health to remove from the player</param>
    public void DamagePlayer(float damage)
    {
        if (!isInvunerable)
        {
            //Reduce Score when damaged
            ScoreKeeper.CurrentScore -= damageScoreReduction;

            //Calculate the resultant health and make sure that it doesn't
            //go below zero
            float resultantHealth = playerHealth - damage;

            if (resultantHealth > 0)
            {
                //Call damage events and functionality
                playerHealth = resultantHealth;
                PlayerDamaged?.Invoke(playerHealth);

                //Set player to be invunerable for an amount of time
                //so they don't take damage 100 times while clipping through a wall
                StartCoroutine(DoInvunerableSequence(playerInvunerableTime));
            }
            else
            {
                //Call game over/death events
                playerHealth = 0;
                PlayerKilled?.Invoke();
            }
        }
    }
Beispiel #3
0
    public void Respawn()
    {
        AudioManager.PlaySound(AudioManager.Sound.Confirm);
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible   = false;
        PlayerRespawned?.Invoke();
        impact        = Vector3.zero;
        isDead        = false;
        canMove       = true;
        canRun        = true;
        currentHealth = maxHealth;
        PlayerDamaged?.Invoke(currentHealth, maxHealth);
        stamina = maxStamina;
        StaminaChanged?.Invoke(stamina, maxStamina);
        var respawnPosition = new Vector3(152.2615f, 1, 142.5762f);

        // turn off characterController so that it does not override transform.position
        characterController.enabled   = false;
        gameObject.transform.position = respawnPosition;
        characterController.enabled   = true;

        onFireTimer    = 5;
        bleedingTimer  = 10;
        exhaustedTimer = 5;

        animator.SetBool("isDying", false);
        animator.SetBool("isRunning", false);
        animator.SetBool("isAttacking", false);
        animator.SetBool("isIdle", true);
    }
    public void Damage(DamageInfo damage)
    {
        if (damage.Value < 0)
        {
            Debug.LogWarning("Damange less than 0.");
            return;
        }
        var value = ApplyArmourRating(damage.Value, damage.DamageType);

        // Debug.Log(damage.Value + ", " + value);

        CurrentHealth -= value;

        if (CurrentHealth < 0)
        {
            CurrentHealth = 0;
        }

        PlayerDamaged?.Invoke(CurrentHealth);

        if (CurrentHealth == 0)
        {
            OnDeath();
        }
    }
Beispiel #5
0
 void OnAnotherDamageEvent(PlayerDamaged e)
 {
     if (e.playerNum == playerNum)
     {
         SetStatus(TaskStatus.Aborted);
     }
 }
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.collider.tag == "Holywall")
        {
            _playerLifesCount--;

            if (_playerLifesCount == 0)
            {
                _Died = true;
                animator.SetTrigger("PlayerDamaged");
                PlayerDie();
            }
            else
            {
                audioSource.PlayOneShot(holyWall);
                PlayerDamaged?.Invoke(_playerLifesCount);
                _isShoked = true;
                animator.SetTrigger("PlayerDamaged");

                Vector3 playerPushDirection = playerCenter.position - collision.contacts[0].point;
                playerPushDirection.y = 0f;

                rigidbody.AddForce((playerPushDirection).normalized * playerPushFromHolyWallForce, ForceMode.Impulse);

                float returnToNormal = 0f;
                DOTween.To(() => returnToNormal, x => returnToNormal = x, 1, 1f).OnComplete(() => { _isShoked = false; });
            }
        }
    }
Beispiel #7
0
    void OnTriggerEnter(Collider other)
    {
        InteractionPrompt.Invoke(this.Interactables.Count > 0);

        switch (other.tag)
        {
        case "Enemy Weapon":
            if (isVulnerable)
            {
                this.SetState(new TakeDamageState(this));
                PlayerDamaged.Invoke();
            }
            break;

        case "Health":
            if (health < maxHealth)
            {
                health += 2;

                if (health > 10)
                {
                    health = 10;
                }

                HealthPickup.Invoke();
                Audio.PlayOneShot(healthPick);

                other.gameObject.SetActive(false);
            }
            break;
        }
    }
Beispiel #8
0
 // Use this for initialization
 void Awake()
 {
     //取得
     player_Controller = transform.parent.GetComponent <PlayerController>();
     player_Damaged    = transform.parent.GetComponent <PlayerDamaged>();
     //初期値代入
     default_Size   = GetComponent <CapsuleCollider2D>().size;
     default_Offset = GetComponent <CapsuleCollider2D>().offset;
 }
    private void OnCollisionEnter2D(Collision2D collision)
    {
        //Check if we have collided with a bullet
        Bullet hitBullet;

        if (collision.gameObject.TryGetComponent <Bullet>(out hitBullet))
        {
            //Don't do damange if we didn't create this
            if (hitBullet.creatorTag != this.gameObject.tag)
            {
                Health -= hitBullet.BulletDamage;
                PlayerDamaged?.Invoke();
                Debug.Log(health);
            }
        }
    }
Beispiel #10
0
    public void TakeDamage(int amount)
    {
        currentHealth -= amount;
        AudioSource.PlayClipAtPoint(damagedClip, transform.position);
        PlayerDamaged?.Invoke();

        if (currentHealth <= 0)
        {
            DisablePlayer();
        }

        healthBar.value = currentHealth;

        StartCoroutine(FlashPlayerRed());

        playerController.RumbleController();
    }
 protected override void CheckTypeAndValues(DamagebleParam.ParamType type, float value, float maxValue)
 {
     switch (type)
     {
     case DamagebleParam.ParamType.Health:
         if (isFirstCheck)
         {
             playerUI.InitializePlayerView(maxValue);
             isFirstCheck = false;
         }
         else
         {
             PlayerDamaged?.Invoke();
         }
         playerUI.ViewHealth(value);
         break;
     }
 }
Beispiel #12
0
    public void ReceiveDamage(float Damage)
    {
        Damage *= damageModifier;

        if (Damage > 0 && !isDead)
        {
            AudioManager.PlaySound(AudioManager.Sound.PlayerDamaged);
        }

        currentHealth -= Damage;
        if (currentHealth < 0)
        {
            currentHealth = 0;
        }
        else if (currentHealth > maxHealth)
        {
            currentHealth = maxHealth;
        }
        PlayerDamaged?.Invoke(currentHealth, maxHealth);
    }
Beispiel #13
0
 private void OnPlayerDamaged(int oldHealth, int newHealth)
 {
     PlayerDamaged?.Invoke();
 }
Beispiel #14
0
 public void PlayerTookDamageAdding(PlayerDamaged registered)
 {
     playerTookDamage += registered;
 }
Beispiel #15
0
 public static void CallPlayerDamaged(float damage)
 {
     PlayerDamaged?.Invoke(damage);
 }
Beispiel #16
0
 private void OnPlayerHit(PlayerDamaged e)
 {
     PlayParticles();
 }
Beispiel #17
0
 public void OnPlayerDamaged(PlayerDamagedEventArgs args)
 {
     PlayerDamaged?.Invoke(this, args);
 }
Beispiel #18
0
 // Use this for initialization
 void Start()
 {
     //取得
     player_Damaged = transform.parent.GetComponent <PlayerDamaged>();
 }
 public void SetHealth(int hp)
 {
     CurrentHealth = Mathf.Clamp(hp, 0, MaxHealth);
     PlayerDamaged?.Invoke(CurrentHealth);
 }