private void OnUnitReached(GuardMovementUnit unitReached) { transform.position = startPosition + unitReached.GetPoint(); isFirstMove = true; IncrementNextUnit(unitReached); }
protected override void Move(GuardMovementUnit curUnit) { // Get the current move point; Vector2 curTargetPos = startPosition + curUnit.GetPoint(); Vector2 curMoveDir = (curTargetPos - (Vector2)transform.position).normalized; // Once we reach our destination if (!isFirstMove && curMoveDir != lastMoveDir) { OnUnitReached(curUnit); return; } isFirstMove = false; lastMoveDir = curMoveDir; FaceDirection(curMoveDir); IncrementPosition(curMoveDir); }
// Called 0th // Domestic Initialization private void Update() { // Don't move if we have no path if (moveUnits.Length == 0) { return; } // Don't move if we shouldn't if (!shouldMove) { return; } // Wait if (waitTimer < timeToWait) { waitTimer += Time.deltaTime; return; } GuardMovementUnit curUnit = moveUnits[curIndex]; Move(curUnit); }
protected abstract void Move(GuardMovementUnit curUnit);
/// <summary> /// Increments the index to the next one and updates the waiting timer /// using the given unit. /// </summary> protected void IncrementNextUnit(GuardMovementUnit unitReached) { curIndex = GetNextIndex(); waitTimer = 0; timeToWait = unitReached.GetWaitTime(); }
protected override void Move(GuardMovementUnit curUnit) { FaceDirection(curUnit.GetPoint()); IncrementNextUnit(curUnit); }