コード例 #1
0
    //Deals with removing health, activating damage animations, and checking if dead then trigger death
    private void TakeDamage(Damage damage, bool triggerAnimation)
    {
        if (damage.DamageValue < 0)
        {
            damage.DamageValue = 0;
        }

        characterStats.decreaseHealth(damage.DamageValue);

        //Create a UI Damage Pop up
        DamagePopUpController.CreateDamagePopUp(damage.DamageValue.ToString(), new Vector2(transform.position.x + ThisCollider.bounds.size.x / 4.0f, transform.position.y + ThisCollider.bounds.size.y / 2.0f), damage.IsCrit, damage.damageType);

        if (triggerAnimation)
        {
            if (ThisAnimator != null)
            {
                ThisAnimator.SetTrigger("damage");
                // play hit audio
                if (gameObject.tag == "Player")
                {
                    gameObject.GetComponent <PlayerControllerScript> ().playHitSound();
                }
                else if (gameObject.tag == "Enemy")
                {
                    gameObject.GetComponent <Enemy> ().playHitSound();
                }
            }
        }

        if (IsDead())
        {
            Die();
        }
    }
コード例 #2
0
    protected void Die()
    {
        if (ThisAnimator != null)
        {
            ThisAnimator.SetTrigger("death");

            if (gameObject.tag == "Player")
            {
                gameObject.GetComponent <PlayerControllerScript>().Restart();
            }
            //Destroy After animation length
            AnimatorClipInfo[] clipInfo = ThisAnimator.GetCurrentAnimatorClipInfo(0);

            int index = -1;

            for (int i = 0; i < clipInfo.Length; i++)
            {
                if (clipInfo[i].clip.name == "die")
                {
                    index = i;
                }
            }

            if (index != -1)
            {
                DeleteCharacter(clipInfo[index].clip.length);
            }
        }

        else
        {
            //If has no death animation then just destroy the object
            DeleteCharacter(0.0f);
        }
    }
コード例 #3
0
    void attack()
    {
        if (Input.GetMouseButtonDown(0))            // left click
        {
            string nextAttack = getNextAttack();
            if (nextAttack == "attack1" || nextAttack == "attack3" || nextAttack == "attack4" || nextAttack == "attack6")
            {
                audioSource1.Stop();
                audioSource1.clip = clips [0];
                audioSource1.Play();
                //	//playSounds ();
            }
            else if (nextAttack == "attack2" || nextAttack == "attack5")
            {
                audioSource1.Stop();
                audioSource1.clip = clips [1];
                audioSource1.Play();
            }

            if (PlayerState != PlayerState.Demon)
            {
                ThisAnimator.SetTrigger(nextAttack);
            }
            else
            {
                ThisAnimator.SetTrigger("DemonMelee");
            }


            IsAttacking = true;
        }
    }
コード例 #4
0
 void dodge()
 {
     if (GetComponent <PlayerScript>().getGrounded() == true)
     {
         if (Input.GetKey(KeyCode.LeftAlt) && characterStats.Stamina >= dodgeCost)
         {
             ThisAnimator.SetTrigger("dodge");
             base.characterStats.decreaseStamina(dodgeCost);
             rigidBody.velocity = new Vector2(0, 0);
             SetFacingDirection();
             if (isFacingRight)
             {
                 rigidBody.AddForce(new Vector2(dodgeForce, 0));
             }
             else
             {
                 rigidBody.AddForce(new Vector2(-dodgeForce, 0));
             }
             IsDodging = true;
         }
     }
 }
コード例 #5
0
 public void EnableBlock()
 {
     ThisAnimator.SetTrigger("initialBlock");
     setIsBlocking(true);
     shield.GetComponent <BoxCollider2D>().enabled = true;
 }