예제 #1
0
        void Update()
        {
            if (_gameState == GameState.GameEnd)
            {
                if (!_wait.Check())
                {
                    _actor.Attack();
                    return;
                }

                _actor.Stand(0);
                return;
            }

            if (_gameState == GameState.Follow)
            {
                switch (_actionState)
                {
                case ActionState.Turn:
                    _actor.Turn(Random.Range(60, 60));
                    _actionState = ActionState.Run;
                    break;

                case ActionState.Run:
                    _actor.Run();
                    var ray = new Ray(this.transform.position,
                                      (_follow.transform.position - transform.position).normalized);
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit))
                    {
                        if (hit.transform.gameObject.GetComponent <Player>() != null)
                        {
                            _actionState = ActionState.FindPlayer;
                        }
                    }
                    break;

                case ActionState.FindPlayer:
                    _actor.FollowPlayer(_follow);
                    break;
                }
                return;
            }

            if (_actionState == ActionState.FindPlayer)
            {
                if (!_wait.Check())
                {
                    _actor.FindPlayer();
                    return;
                }

                _gameState = GameState.Follow;
                return;
            }

            if (_actionState == ActionState.Stand && _wait.Check())
            {
                StartWalkOrRun();
            }

            switch (_actionState)
            {
            case ActionState.Stand:
                _actor.Stand(_waitNumber);
                break;

            case ActionState.Walk:
                _actor.Walk();
                break;

            case ActionState.Run:
                _actor.Run();
                break;

            case ActionState.Turn:
                _actor.Turn(Random.Range(-60, 60));
                StartStand();
                break;
            }
        }