/// <summary>
    /// 当前关卡完成
    /// </summary>
    /// <returns></returns>
    IEnumerator LevelComplete()
    {
        //激活慢动作效果
        if (activateSlowMotionOnLastHit)
        {
            CameraSlowMotion csm = Camera.main.GetComponent <CameraSlowMotion>();
            if (csm != null)
            {
                csm.StartSlowMotionDelay(effectDuration);
                yield return(new WaitForSeconds(effectDuration));
            }
        }

        //进入下一关等待时间
        yield return(new WaitForSeconds(1f));

        //完成关卡后调用UI

        UIManager UI = GameObject.FindObjectOfType <UIManager>();

        if (UI != null)
        {
            UI.UI_fader.Fade(UIFader.FADE.FadeOut, 2f, 0);
            yield return(new WaitForSeconds(2f));
        }

        GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
        foreach (GameObject p in players)
        {
            Destroy(p);
        }

        //进入下一关
        if (loadNewLevel)
        {
            if (levelName != "")
            {
                SceneManager.LoadScene(levelName);
            }
        }
        else
        {
            //展示游戏结束界面
            if (UI != null)
            {
                UI.DisableAllScreens();
                UI.ShowMenu("LevelComplete");
            }
        }
    }
Example #2
0
    /// <summary>
    /// 被击中
    /// </summary>
    /// <param name="d"></param>
    public void Hit(DamageObject d)
    {
        if (HitableStates.Contains(enemyState))
        {
            //只在敌人被击倒时才允许地面攻击击中
            if (enemyState == PLAYERSTATE.KNOCKDOWNGROUNDED && !d.isGroundAttack)
            {
                return;
            }

            CancelInvoke();
            StopAllCoroutines();
            playerAnimator.StopAllCoroutines();
            Move(Vector3.zero, 0f);

            //增加攻击时间,使玩家被击中后无法立即攻击
            lastAttackTime = Time.time;

            //当敌人在空中时不能被击中
            if ((enemyState == PLAYERSTATE.KNOCKDOWNGROUNDED || enemyState == PLAYERSTATE.GROUNDHIT) && !d.isGroundAttack)
            {
                return;
            }

            //防御
            if (!d.DefenceOverride && defendableStates.Contains(enemyState))
            {
                int rand = Random.Range(0, 100);
                if (rand < defendChance)
                {
                    Defend();
                    return;
                }
            }

            //受伤音效
            GlobalAudioPlayer.PlaySFXAtPosition(d.hitSFX, transform.position);

            //被命中后展示特效
            ShowHitEffectAtPosition(new Vector3(transform.position.x, d.inflictor.transform.position.y + d.collHeight, transform.position.z));

            //相机抖动
            CameraShake camShake = Camera.main.GetComponent <CameraShake>();
            if (camShake != null)
            {
                camShake.Shake(0.1f);
            }

            //激活慢动作相机
            if (d.slowMotionEffect)
            {
                CameraSlowMotion cmd = Camera.main.GetComponent <CameraSlowMotion>();
                if (cmd != null)
                {
                    cmd.StartSlowMotionDelay(.2f);
                }
            }

            //减少生命值
            HealthSystem hs = GetComponent <HealthSystem>();
            if (hs != null)
            {
                hs.SubstractHealth(d.damageCount);
                if (hs.CurrentHp == 0)
                {
                    return;
                }
            }

            //地面攻击
            if (enemyState == PLAYERSTATE.KNOCKDOWNGROUNDED)
            {
                StopAllCoroutines();
                enemyState = PLAYERSTATE.GROUNDHIT;
                StartCoroutine(GroundHit());
                return;
            }

            //转向攻击来袭的方向
            int dir = d.inflictor.transform.position.x > transform.position.x ? 1 : -1;
            TurnToDir((DIRECTION)dir);

            //检查是否被击倒
            if (d.knockDown)
            {
                StartCoroutine(KnockDownSequence(d.inflictor));
                return;
            }
            else
            {
                //默认攻击
                int rand = Random.Range(1, 3);
                playerAnimator.SetAnimatorTrigger("Hit" + rand);
                enemyState = PLAYERSTATE.HIT;

                //从冲击中增加很小的力量
                LookAtTarget(d.inflictor.transform);
                playerAnimator.AddForce(-KnockbackForce);

                //受到攻击时将敌人的状态从被动变为主动
                if (enemyTactic != ENEMYTACTIC.ENGAGE)
                {
                    EnemyManager.SetAgressive(gameObject);
                }

                Invoke("Ready", hitRecoveryTime);
                return;
            }
        }
    }