public void ExecuteState()
        {
            switch (_state)
            {
            case State.Neutral:
                _agent.SetDestination(_goalPosition);
                _state = State.GoSomewhere;
                return;

            case State.GoSomewhere:
                if (_agent.HasReachedTarget())
                {
                    _agent.ResetPath();
                    _waitUntill = Time.time + WaitingTime;
                    _state      = State.WaitSomeTime;
                }
                return;

            case State.WaitSomeTime:
                _agent.ResetPath();
                if (Time.time > _waitUntill)
                {
                    _state = State.Done;
                }
                return;

            default:
                return;
            }
        }
Exemplo n.º 2
0
 private void Update()
 {
     if (_targetIsNotHit)
     {
         if (_sideKickAgent.HasReachedTarget())
         {
             _targetIsNotHit = false;
             _sideKickAgent.Stop();
             WaypointAction action = _currentWayPoint.gameObject.GetComponent <WaypointAction>();
             if (action != null)
             {
                 action.SideKickPerformAction();
             }
             _player.ResetPath();
             _player.Resume();
             GoToNextWaypoint();
         }
     }
 }
Exemplo n.º 3
0
        public void ExecuteState()
        {
            // Make sure we go back to default speed

            _agent.speed = _movementSpeed;

            if (_movementSpeed < 0.1f)
            {
                return;
            }



            // Continue only if we have reached taget, or the room numner has changes
            if (!_agent.HasReachedTarget())
            {
                return;
            }
            PickWaypoint();
        }
        public void ExecuteState()
        {
            switch (_state)
            {
            case State.Neutral:
                var pos = _intaractableGoal.InteractPosition(_agent.transform.position);
                _interactGoalPosition = new Vector2(pos.x, pos.z);
                _agent.SetDestination(pos);
                _state = State.GoToIntactable;
                return;

            case State.GoToIntactable:
                if (_agent.HasReachedTarget())
                {
                    _agent.ResetPath();

                    if (_agent.enabled)
                    {
                        cam.StartAdjustPosition(_interactGameObject);
                    }

                    _agent.ResetPath();

                    if (_agent.updateRotation)
                    {
                        _agent.ResetPath();
                        var t = Vector2.Distance(_interactGoalPosition,
                                                 new Vector2(_agent.transform.position.x, _agent.transform.position.z));
                        _state = t < .6 ? State.Interact : State.Done;
                    }
                }
                return;

            case State.Interact:
                var puh = _agent.gameObject.GetComponent <PickupHandler>();


                if (_interactGameObject.tag == Constants.Tags.Lever && _intaractableGoal.CanThisBeInteractedWith(puh.CurrentPickup))
                {
                    _agent.gameObject.GetComponent <Animator>().SetTrigger("PullLever");
                }
                else if (_interactGameObject.tag == Constants.Tags.Brazier && _intaractableGoal.CanThisBeInteractedWith(puh.CurrentPickup))
                {
                    _agent.gameObject.GetComponent <Animator>().SetTrigger("LightFire");
                }
                else if (_interactGameObject.tag == Constants.Tags.Keyhole)
                {
                    if (_intaractableGoal.CanThisBeInteractedWith(puh.CurrentPickup))
                    {
                        _agent.gameObject.GetComponent <Animator>().SetTrigger("OpenDoor");
                    }
                    else
                    {
                        _agent.gameObject.GetComponent <Animator>().SetTrigger("DoorLocked");
                    }
                }
                else if (_interactGameObject.tag == Constants.Tags.Key ||
                         _interactGameObject.tag == Constants.Tags.Stick)
                {
                    _agent.gameObject.GetComponent <Animator>().SetTrigger("PickUp");
                }

                var returnItem = _intaractableGoal.Interact(puh.CurrentPickup);
                puh.PickUpItem(returnItem);
                _agent.ResetPath();

                _waitUntill = Time.time + WaitingTime;
                _state      = State.WaitSomeTime;
                return;

            case State.WaitSomeTime:
                _agent.ResetPath();
                if (_waitUntill < Time.time)
                {
                    _state = State.Done;
                }
                return;

            default:
                return;
            }
        }
Exemplo n.º 5
0
        public void ExecuteState()
        {
            if (_pickupGoal == null || !_pickupGoal.activeSelf)
            {
                _state = State.Done;
            }

            switch (_state)
            {
            case State.Neutral:
                _agent.destination = _pickupGoal.transform.position;
                _state             = State.GoToPickup;
                return;

            case State.GoToPickup:
                if (_agent.HasReachedTarget())
                {
                    _state = State.PickupAnim;
                }
                return;

            case State.PickupAnim:     //1.1
                if (_pickupGoal.GetComponent <ICollectable>() == null)
                {
                    throw new Exception("You cannot make the AI pick up an item, without it having a ICollectable script attached!");
                }
                if (Vector3.Distance(_pickupGoal.transform.position, _agent.transform.position) < 2)
                {
                    _agent.ResetPath();
                }
                if (Vector3.Distance(_pickupGoal.transform.position, _agent.transform.position) < 2 && _agent.gameObject.GetComponent <Animator>().GetCurrentAnimatorStateInfo(0).IsName("StandingStill"))
                {
                    _agent.gameObject.GetComponent <Animator>().SetTrigger("PickUp");
                    _state     = State.PickupAction;
                    _waitUntil = Time.time + 1.2f;
                }
                return;

            case State.PickupAction:
                if (_pickupGoal.GetComponent <ICollectable>() == null)
                {
                    throw new Exception("You cannot make the AI pick up an item, without it having a ICollectable script attached!");
                }
                if (_waitUntil < Time.time)
                {
                    var pickup = _pickupGoal.GetComponent <ICollectable>().PickUp();
                    _agent.gameObject.GetComponent <AiMovement>().FindPickUpHandeder().PickUpItem(pickup);
                    _waitUntil = Time.time + WaitingTime;
                    _agent.ResetPath();
                    _state = State.Wait;
                }
                return;

            case State.Wait:
                if (Time.time > _waitUntil)
                {
                    _state = State.Done;
                }
                return;

            default:
                return;
            }
        }