/// <summary> /// Pushs the and instantiate random component. /// </summary> /// <returns>The instantiated random component.</returns> /// <param name="useStartingComponent">True will load the first component of the level group</param> private LevelComponent PushAndInstantiateRandomComponent(bool useStartingComponent = false, bool tutMode = false) { LevelComponent newComponent = null; if (useStartingComponent) { newComponent = mCurrentLevelGroup.GetStartLevelComponent(); } else if (tutMode) { newComponent = mCurrentLevelGroup.GetTutorialLevelComponent(); } else { newComponent = mCurrentLevelGroup.GetRandomComponent(); } newComponent.ParentGroup = mCurrentLevelGroup; // Set its position to the last max point (I hope). newComponent.transform.position = mLastCenterPosition; // Get the min of the new component Transform minAnchor = newComponent.transform.FindChild("AnchorMin"); // Determine the vector that we need to push the center by Vector3 pushVector = newComponent.transform.position - minAnchor.position; // And push it newComponent.transform.position += pushVector; // Update the next position as this ones max anchor Transform maxAnchor = newComponent.transform.FindChild("AnchorMax"); mLastCenterPosition = maxAnchor.position; mLevelComponentQueue.Enqueue(newComponent); PopulateLevelComponent(newComponent); return(newComponent); }