コード例 #1
0
 public override void Enter()
 {
     base.Enter();
     _anim              = _go.GetComponent <Animator>();
     _enemyAction       = _go.GetComponent <EnemyAction2>();
     _alreadBlocking    = false;
     _blockingCountDown = 5f;
 }
コード例 #2
0
 void Start()
 {
     _anim = GetComponent <Animator>();
     _anim.runtimeAnimatorController = Resources.Load <RuntimeAnimatorController>("AnimationController/EnemyAnimator"); //Load controller at runtime https://answers.unity.com/questions/1243273/runtimeanimatorcontroller-not-loading-from-script.html
     enemyAction = GetComponent <EnemyAction2>();
     //collider = this.enemy.transform.Find("mixamorig:Hips/mixamorig:Spine/mixamorig:Spine1/mixamorig:Spine2/mixamorig:RightShoulder/mixamorig:RightArm/mixamorig:RightForeArm/mixamorig:RightHand/" +
     //    "katana").gameObject.GetComponent<BoxCollider>(); // to find a child game object by name   //https://docs.unity3d.com/ScriptReference/Transform.Find.html
 }
コード例 #3
0
 public override void Enter()
 {
     base.Enter();
     _anim                 = _go.GetComponent <Animator>();
     _enemyAction          = _go.GetComponent <EnemyAction2>();
     _playerTransform      = GameObject.FindGameObjectWithTag("Player").transform;
     _rnd                  = new Random();
     _attackStateCountDown = 7f;
 }
コード例 #4
0
 void Start()
 {
     enemyAction = enemy.GetComponent <EnemyAction2>();
     //enemy = this.transform.root.Find("EnemyHolder/Enemy").gameObject;
 }
コード例 #5
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Enemy")
        {
            Enemy              enemy          = collision.gameObject.GetComponent <Enemy>();
            EnemyAction2       enemyAction    = collision.gameObject.GetComponent <EnemyAction2>();
            EnemyAnimationCopy enemyAnimation = collision.gameObject.GetComponent <EnemyAnimationCopy>();

            #region Enemy Blocking Collision Logic
            // enemy is blocking and get hit by player
            if (this.GetComponent <Collider>().isTrigger == false &&
                enemyAction.isKeepBlocking == true &&
                enemyAction.isPerfectBlock == false &&
                enemyAnimation._anim.GetCurrentAnimatorStateInfo(0).IsTag("B"))
            {
                #region get player heavy attack
                if (enemy.hitStunValue > 0 &&
                    playerAnimation._anim.GetCurrentAnimatorStateInfo(0).IsTag("HT"))
                {
                    playerStats.hitStunValue -= 100;
                    if (playerStats.hitStunValue <= 0)
                    {
                        enemy.DecreaseHPStamina(10, 10);
                        enemy.readyToRestoreStaminaTime = 5.0f;
                        enemyAnimation._anim.ResetTrigger("isInjured");
                        enemyAnimation._anim.SetTrigger("isInjured");
                    }
                }
                #endregion

                #region get enemy light attack
                //get enemy light attack
                if (enemy.hitStunValue > 0 &&
                    playerAnimation._anim.GetCurrentAnimatorStateInfo(0).IsTag("LT"))
                {
                    enemy.DecreaseHPStamina(1.25f, 1.25f);
                    enemy.hitStunValue             -= 10;
                    enemy.hitStunRestoreSecond      = 5.0f;
                    enemy.readyToRestoreStaminaTime = 5.0f;

                    if (enemy.hitStunValue > 0)
                    {
                        enemyAnimation._anim.ResetTrigger("isGetBlockingImpact");
                        enemyAnimation._anim.SetTrigger("isGetBlockingImpact");

                        // spawn sword clash effect
                        enemy.GetComponent <SwordEffectSpawner>().SpawnSwordClash();
                    }

                    else if (enemy.hitStunValue <= 0)
                    {
                        enemy.DecreaseHPStamina(5, 5);
                        enemy.readyToRestoreStaminaTime = 5.0f;
                        enemyAnimation._anim.ResetTrigger("isInjured");
                        enemyAnimation._anim.SetTrigger("isInjured");
                    }
                }
                #endregion
                this.GetComponent <Collider>().isTrigger = true;
            }

            // enemy is in blocking impact status and get hit
            if (this.GetComponent <Collider>().isTrigger = false &&
                                                           enemyAction.isKeepBlocking == true &&
                                                           enemyAction.isPerfectBlock == false &&
                                                           enemyAnimation._anim.GetCurrentAnimatorStateInfo(0).IsTag("BI"))
            {
                enemy.hitStunValue -= 20;
                enemyAnimation._anim.ResetTrigger("isGetBlockingImpact");
                enemyAnimation._anim.SetTrigger("isGetBlockingImpact");
                this.GetComponent <Collider>().isTrigger = true;

                // spawn sword clash effect
                enemy.GetComponent <SwordEffectSpawner>().SpawnSwordClash();
            }
            #endregion

            // enemy is not in block action and get hit by player (Heavy attack)
            if (playerAnimation._anim.GetCurrentAnimatorStateInfo(0).IsTag("HT") &&
                this.GetComponent <Collider>().isTrigger == false &&
                enemyAction.isKeepBlocking == false &&
                enemyAction.isPerfectBlock == false)
            {
                this.GetComponent <Collider>().isTrigger = true;
                enemy.DecreaseHPStamina(10, 10);   //  actual is 20
                enemy.readyToRestoreStaminaTime = 5.0f;
                //playerMovement.isSprinting = false;
                enemyAnimation._anim.ResetTrigger("isInjured");
                enemyAnimation._anim.SetTrigger("isInjured");
            }

            // enemy is not in block action and get hit by player  (light attack)
            else if (playerAnimation._anim.GetCurrentAnimatorStateInfo(0).IsTag("LT") &&
                     this.GetComponent <Collider>().isTrigger == false &&
                     enemy.GetComponent <EnemyAction2>().isKeepBlocking == false &&
                     enemyAction.isPerfectBlock == false)
            {
                this.GetComponent <Collider>().isTrigger = true;
                enemy.DecreaseHPStamina(5, 5);  //  actual is 10
                enemy.readyToRestoreStaminaTime = 5.0f;
                enemyAnimation._anim.ResetTrigger("isInjured");
                enemyAnimation._anim.SetTrigger("isInjured");
            }

            // enemy is in perfect block Transistion but not in perfect block timing (Heavy attack)
            // (GetCurrentAnimatorStateInfo(0).IsTag("PB")) get current animator state by tag https://forum.unity.com/threads/current-animator-state-name.331803/
            else if ((enemyAnimation._anim.GetCurrentAnimatorStateInfo(0).IsTag("PB") ||
                      enemyAnimation._anim.GetCurrentAnimatorStateInfo(0).IsTag("A") ||
                      enemyAnimation._anim.GetCurrentAnimatorStateInfo(0).IsTag("PBO")) &&
                     enemyAction.isPerfectBlock == false &&
                     playerAnimation._anim.GetCurrentAnimatorStateInfo(0).IsTag("HT"))
            {
                enemy.DecreaseHPStamina(10, 10);  //  actual is 20
                enemy.readyToRestoreStaminaTime = 5.0f;
                enemyAnimation._anim.ResetTrigger("isInjured");
                enemyAnimation._anim.SetTrigger("isInjured");
                // playerMovement.isSprinting = false;
                this.GetComponent <Collider>().isTrigger = true;
            }

            // enemy is in perfect block Transistion but not in perfect block timing (light attack)
            else if ((enemyAnimation._anim.GetCurrentAnimatorStateInfo(0).IsTag("PB") ||
                      enemyAnimation._anim.GetCurrentAnimatorStateInfo(0).IsTag("A") ||
                      enemyAnimation._anim.GetCurrentAnimatorStateInfo(0).IsTag("PBO")) &&
                     enemyAction.isPerfectBlock == false &&
                     enemyAction.isKeepBlocking == true &&
                     playerAnimation._anim.GetCurrentAnimatorStateInfo(0).IsTag("LT"))
            {
                enemy.DecreaseHPStamina(5, 5);   //  actual is 10
                enemy.hitStunValue -= 5;
                enemyAnimation._anim.ResetTrigger("isGetBlockingImpact");
                enemyAnimation._anim.SetTrigger("isGetBlockingImpact");
                enemy.readyToRestoreStaminaTime = 5.0f;
                //playerMovement.isSprinting = false;
                this.GetComponent <Collider>().isTrigger = true;
                enemy.GetComponent <SwordEffectSpawner>().SpawnSwordClash();
            }

            else if (enemyAnimation._anim.GetCurrentAnimatorStateInfo(0).IsTag("GH"))
            {
                if (playerAnimation._anim.GetCurrentAnimatorStateInfo(0).IsTag("LT"))
                {
                    enemy.DecreaseHPStamina(5, 5);   //  actual is 10
                }
                else if (playerAnimation._anim.GetCurrentAnimatorStateInfo(0).IsTag("HT"))
                {
                    enemy.DecreaseHPStamina(10, 10);   //  actual is 20
                }
                enemyAnimation._anim.ResetTrigger("isInjured");
                enemyAnimation._anim.SetTrigger("isInjured");
                enemy.readyToRestoreStaminaTime = 5.0f;
            }

            // enemy is in perfect block
            if (enemyAction.isPerfectBlock == true)
            {
                player.GetComponent <PlayerAnimation>()._anim.ResetTrigger("isGetEnemyPerfectBlock");
                player.GetComponent <PlayerAnimation>()._anim.SetTrigger("isGetEnemyPerfectBlock");
                playerAction.isPlayerAttacking = false;
                playerStats.isHitStun          = true;

                // spawn sword clash effect
                collision.gameObject.GetComponentInParent <SwordEffectSpawner>().SpawnBigSwordClash();
                this.GetComponent <Collider>().isTrigger = true;
            }
            this.GetComponent <Collider>().isTrigger = true;
        }
    }