Beispiel #1
0
        // Update is called once per frame
        void Update()
        {
            if (waitSomeTimeDelay.IsWaiting)
            {
                return;
            }

            // Check if arrived at the current destination.
            if (IsArrivedAtDestnConditional.IsArrivedAtDestination(currDestn, transform.position, 0.1f, isVertical))
            {
                // Set the next destination.
                currDestn = (currDestn == pointA.position) ? pointB.position : pointA.position;
                // Wait some time before moving to the next position.
                waitSomeTimeDelay.Start(this);
                return;
            }

            // Calculate the movement to be added.
            Vector2 mvmtToAdd;

            if (isVertical)
            {
                mvmtToAdd = new Vector2(0, speed * Time.fixedDeltaTime * ((currDestn.y > transform.position.y) ? 1 : -1));
            }
            else
            {
                mvmtToAdd = new Vector2(speed * Time.fixedDeltaTime * ((currDestn.x > transform.position.x) ? 1 : -1), 0);
            }

            UpdatePassengersPos(mvmtToAdd);
        }
Beispiel #2
0
        protected override void BuildBehavior()
        {
            Conditional isAttacking = new IsAttackingConditional(charDriver);

            Conditional    isTargetInRange = new IsTargetInRangeConditional(charDriver, targetLayer, range);
            BehaviorAction attack          = new AttackAAction(charDriver);
            Sequence       checkTargetSeq  = new Sequence(isTargetInRange, attack);

            Conditional isWaiting = new IsWaitingConditional(waitSomeTimeCooldown);

            Conditional    arrivedAtDestn  = new IsArrivedAtDestnConditional(charDriver, GetCurrDestn);
            BehaviorAction stopMvmt        = new StopMovementAction(charDriver, true);
            BehaviorAction pickNextDestn   = new PickNextDestnAction <Transform>(GetPointsToPatrol, GetCurrDestnIndex, SetCurrDestnIndex);
            BehaviorAction waitSomeTime    = new WaitSomeTimeAction(charDriver, waitSomeTimeCooldown);
            Sequence       checkArrivedSeq = new Sequence(arrivedAtDestn, pickNextDestn, stopMvmt, waitSomeTime);

            BehaviorAction moveToDestn      = new MoveToDestnAction(charDriver, GetCurrDestn, run, axisMvmt);
            Selector       checkMovementSel = new Selector(checkArrivedSeq, moveToDestn);

            Selector patrol = new Selector(isAttacking, checkTargetSeq, isWaiting, checkMovementSel);

            behavior = new Behavior(new Sequence(patrol));
        }