void move()
    {
        movex = Input.GetAxis("Horizontal");
        //movey = Input.GetAxis ("Vertical"); we'll use this later for ladders

        //Set run animation based on input
        ThisAnimator.SetFloat("speed", Mathf.Abs(movex));

        //Tell animator the Y velocity
        ThisAnimator.SetFloat("ySpeed", rigidBody.velocity.y);
        if (Mathf.Abs(rigidBody.velocity.x) > 0 && !audioSource2.isPlaying)
        {
            //audioSource2.Play ();
        }
        else if (Mathf.Abs(rigidBody.velocity.x) == 0)
        {
            //audioSource2.Stop ();
        }

        if (canMoveX)
        {
            rigidBody.velocity = new Vector2(IsBlocking? movex * blockSpeed : movex * characterStats.MovementSpeed, rigidBody.velocity.y);
        }

        float x = transform.localScale.x;

        if (movex > 0 && x < 0)
        {
            transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
        }
        else if (movex < 0 && x > 0)
        {
            transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
        }
    }
Exemplo n.º 2
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();
        }
    }
 public void PausePlayerWhileTransforming()
 {
     ThisRigidBody.velocity     = new Vector2(0, 0);
     ThisRigidBody.gravityScale = 0;
     IsTransforming             = true;
     ThisAnimator.SetBool("isTransforming", IsTransforming);
 }
Exemplo n.º 4
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);
        }
    }
    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;
        }
    }
    /// <summary>
    /// アニメーションの初期化
    /// </summary>
    public override void UpdateIdleStatus()
    {
        SetAnimator();

        ThisAnimator.SetSpeed(CommonConst.SystemValue.AnimationSpeedDefault);

        MoveSpeed = MoveSpeedDefault;
    }
Exemplo n.º 7
0
 public void Move()
 {
     //Currently can only move if he is not attacking
     if (!IsAttacking)
     {
         //Tell animator that we are moving
         ThisAnimator.SetFloat("movementSpeed", 1);
         playRunSoundNearPlayer();
         //Translate
         transform.Translate(new Vector3(1 * (characterStats.MovementSpeed * Time.deltaTime), 0, 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;
         }
     }
 }
Exemplo n.º 9
0
 public virtual void OnAttack(bool state = true)
 {
     ThisAnimator.SetBool("OnAttack", state);
 }
Exemplo n.º 10
0
 public void OffAllAnimation()
 {
     SetAnimator();
     ThisAnimator.OffAllAction();
 }
 public void EnableBlock()
 {
     ThisAnimator.SetTrigger("initialBlock");
     setIsBlocking(true);
     shield.GetComponent <BoxCollider2D>().enabled = true;
 }
 public void ResumePlayerAfterTransformation()
 {
     ThisRigidBody.gravityScale = initialGravityScale;
     IsTransforming             = false;
     ThisAnimator.SetBool("isTransforming", IsTransforming);
 }
 //Tell the animator the current state of the double jump
 private void doubleJumpState()
 {
     //If he can double jump then tell animator that he currently isn't double jumping
     ThisAnimator.SetBool("inDoubleJump", !canDoubleJump);
 }
Exemplo n.º 14
0
 public virtual void OnDisappear(bool state = true)
 {
     ThisAnimator.SetBool("OnDisappear", state);
 }
Exemplo n.º 15
0
    public virtual void OnDead(bool state = true)
    {
        m_fRemainHealth = 0.0f;

        ThisAnimator.SetBool("OnDead", state);
    }
Exemplo n.º 16
0
 public void StopMoving()
 {
     audioSource1.Stop();
     ThisAnimator.SetFloat("movementSpeed", 0);
 }
 private void setIsBlocking(bool value)
 {
     IsBlocking = value;
     ThisAnimator.SetBool("block", IsBlocking);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Author: Ziqi
 /// Implementation of abstract method to trigger moving
 /// </summary>
 public override void IsMoving(float speed)
 {
     ThisAnimator.SetFloat(ParamName_Moving, Mathf.Abs(speed));
 }
Exemplo n.º 19
0
 public virtual void OnHit(bool state = true)
 {
     ThisAnimator.SetBool("OnHit", state);
 }