// move all of the active objects public void MoveObjects(float moveDistance) { if (moveDistance == 0) { return; } // the distance to move the objects Vector3 delta = moveDirection * moveDistance; if (moveDirection != spawnDirection) { wrongMoveDistance += moveDistance; } // only move the top most platform/scene of each ObjectLocation because all of the other objects are children of these two // objects. Only have to check the bottom-most platform/scene as well to determine if it should be removed InfiniteObject infiniteObject = null; Transform objectTransform = null; PlatformObject platformObject = null; for (int i = 0; i < 2; ++i) // loop through the platform and scenes { for (int j = 0; j < (int)ObjectLocation.Last; ++j) { // move infiniteObject = infiniteObjectHistory.GetTopInfiniteObject((ObjectLocation)j, i == 0); if (infiniteObject != null) { objectTransform = infiniteObject.GetTransform(); Vector3 pos = objectTransform.position; pos -= delta; objectTransform.position = pos; // check for removal.. there will always be a bottom object if there is a top object infiniteObject = infiniteObjectHistory.GetBottomInfiniteObject((ObjectLocation)j, i == 0); if (playerTransform.InverseTransformPoint(infiniteObject.GetTransform().position).z < removeHorizon) { // if the infinite object is a platform and it has changes height, move everything down by that height if (heightReposition && i == 1) // 1 are platforms { platformObject = infiniteObject as PlatformObject; if (platformObject.slope != PlatformSlope.None) { TransitionHeight(platformSizes[platformObject.GetLocalIndex()].y); } } if (turnPlatform[j] == infiniteObject) { turnPlatform[j] = null; } infiniteObjectHistory.ObjectRemoved((ObjectLocation)j, i == 0); infiniteObject.Deactivate(); } } } // loop through all of the turn objects infiniteObject = infiniteObjectHistory.GetTopTurnInfiniteObject(i == 0); if (infiniteObject != null) { objectTransform = infiniteObject.GetTransform(); Vector3 pos = objectTransform.position; pos -= delta; objectTransform.position = pos; infiniteObject = infiniteObjectHistory.GetBottomTurnInfiniteObject(i == 0); if (playerTransform.InverseTransformPoint(infiniteObject.GetTransform().position).z < removeHorizon) { infiniteObjectHistory.TurnObjectRemoved(i == 0); infiniteObject.Deactivate(); } } } if (!stopObjectSpawns) { dataManager.AddToScore(moveDistance); SpawnObjectRun(true); } }