Пример #1
0
    public void Aggro()
    {
        FSMState chaseState = FSMManager.GetState("ZombieChase");

        if (chaseState != null)
        {
            EntityFSM.ChangeState(chaseState);
        }
    }
Пример #2
0
    private void Start()
    {
        //FSM TESTING
        FSMState normalState = FSMManager.GetState("ZombieWander");

        if (normalState != null)
        {
            EntityFSM.ChangeState(normalState);
        }
        else
        {
            Debug.LogError("Can't find Zombie Wander state");
        }
    }
Пример #3
0
        private void Update()
        {
            /// <summary>Status: Move Horizontally when input X is detected</summary>
            float inputX = Input.GetAxisRaw("Horizontal");
            float inputY = Input.GetAxisRaw("Vertical");

            bodyState = myFsmManager.GetState("FullBody");
            direction = myFsmManager.GetState("Direction");

            if (myActor.IsGrounded())
            {
                if (myActor.velocity.x < 0)
                {
                    myFsmManager.TurnOn("Direction", "Left");

                    myFsmManager.TurnOn("FullBody", "Run");
                }
                else if (myActor.velocity.x > 0)
                {
                    myFsmManager.TurnOn("Direction", "Right");

                    myFsmManager.TurnOn("FullBody", "Run");
                }

                if (myActor.velocity.x == 0 &&
                    myActor.velocity.y == 0
                    )
                {
                    myFsmManager.TurnOn("FullBody", "Idle");
                }
            }

            if (myFsmManager.IsOn("Direction", "Left"))
            {
                transform.localScale = new Vector3(-1f, transform.localScale.y, transform.localScale.z);
            }
            else
            {
                transform.localScale = new Vector3(1f, transform.localScale.y, transform.localScale.z);
            }

            // If the character is Dashing, keep the dashing speed until the dash action is unlocked.
            if (myTimer.IsUnlock("DashDuration"))
            {
                // back to the normal speed when dashing is unlocked.
                myActor.velocity.x = Math.Approach(myActor.velocity.x, maxRun * inputX, runAccelerate * Time.deltaTime);
            }
            /// </summary>End Moving Horizontally when input X is detected</summary>

            /// <summary>Status: Move Vertical when input X is detected</summary>
            if (myTimer.IsUnlock("DashDuration"))
            {
                myActor.gravity = gravity;
            }
            else
            {
                myActor.velocity.y = 0;
                myActor.gravity    = 0;
            }
            /// </summary>End Vertical Horizontally when input X is detected</summary>

            /// <summary>Status: Handle Falling</summary>
            if (myActor.velocity.y < 0)
            {
                myFsmManager.TurnOn("FullBody", "Fall");
            }
            /// </summary>End Falling</summary>

            /// <summary>Event: Handle Jumping</summary>
            if (Input.GetButtonDown("Jump") && myActor.IsGrounded())
            {
                myActor.velocity.y = jumpSpeed;
                myFsmManager.TurnOn("FullBody", "Jump");
            }
            // if (myActor.velocity.y < 0) myTimer.UnlockAction ("Jump");
            /// </summary>End Jumping</summary>

            /// <summary>Event: Handle Dashing</summary>
            if (Input.GetKeyDown(KeyCode.Z) && myTimer.IsUnlock("DashLock"))
            {
                myTimer.LockAction("DashDuration", dashDurationTime);
                myTimer.LockAction("DashLock", dashLockTime);
                myFsmManager.TurnOn("FullBody", "Dash");

                if (myFsmManager.IsOn("Direction", "Left"))
                {
                    myActor.velocity.x = -dashSpeed;
                }
                else
                {
                    myActor.velocity.x = dashSpeed;
                }
            }
            /// </summary>End Dashing</summary>

            /// <summary>Event: Handle Attack</summary>
            if (Input.GetKeyDown(KeyCode.X) && isEnabledDamager() &&
                myTimer.IsUnlock("AttackLock"))
            {
                myFsmManager.TurnOn("Action", "Attack");
                myTimer.LockAction("AttackDuration", attackDurationTime);
                myTimer.LockAction("AttackLock", attackLockTime);

                Debug.Log(myDamager.IfOverlapDamageBox());
            }

            if (myTimer.IsUnlock("AttackLock") &&
                myFsmManager.IsOn("Action", "Attack"))
            {
                myFsmManager.TurnOff("Action");
            }
            /// </summary>End Attack</summary>

            /// <summary>Event: Handle Shoot</summary>
            if (Input.GetKey(KeyCode.C) && isEnabledShooter() &&
                myTimer.IsUnlock("ShootLock"))
            {
                myFsmManager.TurnOn("Action", "Shoot");
                myTimer.LockAction("ShootLock", shootLockTime);

                if (myFsmManager.IsOn("Direction", "Left"))
                {
                    myShooter.Fire(Vector3.left);
                }
                else
                {
                    myShooter.Fire(Vector3.right);
                }
            }

            if (Input.GetKeyUp(KeyCode.C) &&
                myFsmManager.IsOn("Action", "Shoot"))
            {
                myFsmManager.TurnOff("Action");
            }
            /// </summary>End Shoot</summary>

            /// <summary>Animator</summary>
            if (myFsmManager.GetState("Action") == null)
            {
                // If no action is performing, only show pure fullbody animation
                if (myFsmManager.IsOn("FullBody", "Idle"))
                {
                    SetAnimation(idleAnimation);
                }

                if (myFsmManager.IsOn("FullBody", "Run"))
                {
                    SetAnimation(runAnimation);
                }

                if (myFsmManager.IsOn("FullBody", "Jump"))
                {
                    SetAnimation(jumpAnimation);
                }

                if (myFsmManager.IsOn("FullBody", "Fall"))
                {
                    SetAnimation(fallAnimation);
                }

                if (myFsmManager.IsOn("FullBody", "Dash"))
                {
                    SetAnimation(dashAnimation);
                }
            }
            else
            {
                switch (myFsmManager.GetState("Action"))
                {
                case "Attack":
                    if (myFsmManager.IsOn("FullBody", "Idle"))
                    {
                        SetAnimation("Attack");
                    }

                    if (myFsmManager.IsOn("FullBody", "Run"))
                    {
                        SetAnimation("Attack");
                    }

                    if (myFsmManager.IsOn("FullBody", "Jump"))
                    {
                        SetAnimation("Attack");
                    }

                    if (myFsmManager.IsOn("FullBody", "Fall"))
                    {
                        SetAnimation("Attack");
                    }

                    if (myFsmManager.IsOn("FullBody", "Dash"))
                    {
                        SetAnimation("Attack");
                    }
                    break;

                case "Shoot":
                    Debug.Log("shooting");
                    break;
                }
            }
        }