Example #1
0
    //Level complete
    IEnumerator LevelComplete()
    {
        //activate slow motion effect
        if (activateSlowMotionOnLastHit)
        {
            CamSlowMotionDelay cmd = Camera.main.GetComponent <CamSlowMotionDelay>();
            if (cmd != null)
            {
                cmd.StartSlowMotionDelay(effectDuration);
                yield return(new WaitForSeconds(effectDuration));
            }
        }

        //Timeout before continuing
        yield return(new WaitForSeconds(1f));

        //Fade to black
        UIManager UI = GameObject.FindObjectOfType <UIManager>();

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

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

        //Go to next level or show GAMEOVER screen
        if (loadNewLevel)
        {
            if (levelName != "")
            {
                SceneManager.LoadScene(levelName);
            }
        }
        else
        {
            //Show game over screen
            if (UI != null)
            {
                UI.DisableAllScreens();
                UI.ShowMenu("LevelComplete");
            }
        }
    }
Example #2
0
    //Unit was hit
    public void Hit(DamageObject d)
    {
        if (HitableStates.Contains(enemyState))
        {
            //only allow ground attacks to hit us when we are knocked down
            if (enemyState == UNITSTATE.KNOCKDOWNGROUNDED && !d.isGroundAttack)
            {
                return;
            }

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

            //add attack time out so this enemy cannot attack instantly after a hit
            lastAttackTime = Time.time;

            //don't hit this unit when it's allready down
            if ((enemyState == UNITSTATE.KNOCKDOWNGROUNDED || enemyState == UNITSTATE.GROUNDHIT) && !d.isGroundAttack)
            {
                return;
            }

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

            //hit sfx
            GlobalAudioPlayer.PlaySFXAtPosition(d.hitSFX, transform.position);

            //hit particle effect
            ShowHitEffectAtPosition(new Vector3(transform.position.x, d.inflictor.transform.position.y + d.collHeight, transform.position.z));

            //camera Shake
            CamShake camShake = Camera.main.GetComponent <CamShake>();
            if (camShake != null)
            {
                camShake.Shake(.1f);
            }

            //activate slow motion camera
            if (d.slowMotionEffect)
            {
                CamSlowMotionDelay cmd = Camera.main.GetComponent <CamSlowMotionDelay>();
                if (cmd != null)
                {
                    cmd.StartSlowMotionDelay(.2f);
                }
            }

            //substract health
            HealthSystem hs = GetComponent <HealthSystem>();
            if (hs != null)
            {
                hs.SubstractHealth(d.damage);
                if (hs.CurrentHp == 0)
                {
                    return;
                }
            }

            //ground attack
            if (enemyState == UNITSTATE.KNOCKDOWNGROUNDED)
            {
                StopAllCoroutines();
                enemyState = UNITSTATE.GROUNDHIT;
                StartCoroutine(GroundHit());
                return;
            }

            //turn towards the direction of the incoming attack
            int dir = d.inflictor.transform.position.x > transform.position.x? 1 : -1;
            TurnToDir((DIRECTION)dir);

            //check for a knockdown
            if (d.knockDown)
            {
                StartCoroutine(KnockDownSequence(d.inflictor));
                return;
            }
            else
            {
                //default hit
                int rand = Random.Range(1, 3);
                animator.SetAnimatorTrigger("Hit" + rand);
                enemyState = UNITSTATE.HIT;

                //add small force from the impact
                LookAtTarget(d.inflictor.transform);
                animator.AddForce(-KnockbackForce);

                //switch  enemy state from passive to aggressive when attacked
                if (enemyTactic != ENEMYTACTIC.ENGAGE)
                {
                    EnemyManager.setAgressive(gameObject);
                }

                Invoke("Ready", hitRecoveryTime);
                return;
            }
        }
    }
Example #3
0
    /// <summary>
    /// 被攻击
    /// </summary>
    /// <param name="d"></param>
    public void Hit(DamageObject d)
    {
        if (HitableStates.Contains(enemyState))
        {
            //只有在第一次被击倒时才能进行地面攻击
            if (enemyState == UNITSTATE.KNOCKDOWNGROUNDED && !d.isGroundAttack)
            {
                return;
            }

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

            //给敌人添加硬直时间
            lastAttackTime = Time.time;

            //在倒地状态只能被攻击一次
            if ((enemyState == UNITSTATE.KNOCKDOWNGROUNDED || enemyState == UNITSTATE.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));

            //相机震动
            CamShake camShake = Camera.main.GetComponent <CamShake>();
            if (camShake != null)
            {
                camShake.Shake(.1f);
            }

            //摄像机慢动作
            if (d.slowMotionEffect)
            {
                CamSlowMotionDelay cmd = Camera.main.GetComponent <CamSlowMotionDelay>();
                if (cmd != null)
                {
                    cmd.StartSlowMotionDelay(.2f);
                }
            }

            //减少HP
            HealthSystem hs = GetComponent <HealthSystem>();
            if (hs != null)
            {
                hs.SubstractHealth(d.damage);
                if (hs.CurrentHp == 0)
                {
                    return;
                }
            }

            //地面攻击
            if (enemyState == UNITSTATE.KNOCKDOWNGROUNDED)
            {
                StopAllCoroutines();
                enemyState = UNITSTATE.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);
                animator.SetAnimatorTrigger("Hit" + rand);
                enemyState = UNITSTATE.HIT;

                //对攻击对象施加力
                LookAtTarget(d.inflictor.transform);
                animator.AddForce(-KnockbackForce);

                //当收到攻击的时候将敌人的状态从被动切换到主动
                if (enemyTactic != ENEMYTACTIC.ENGAGE)
                {
                    EnemyManager.setAgressive(gameObject);
                }

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