// Override to add additional restriction public override bool CanSpawnObject(float distance, ObjectSpawnData spawnData) { if (!base.CanSpawnObject(distance, spawnData)) { return(false); } int platformLocalIndex = ObjectHistory.instance.GetFirstPlatformIndex(); if (platformLocalIndex == -1) { return(false); } // Get the platform that this scene is going to spawn next to. // See if the platform requires linked scenes and if it does, if this scene fulfills that requirement. PlatformObject platform = ObjectPool.instance.GetObjectFromLocalIndex(platformLocalIndex, ObjectType.Platform) as PlatformObject; if (platform.HasLinkedScenes()) { for (int i = 0; i < linkedPlatforms.Count; ++i) { if (linkedPlatforms[i].CanSpawnObject(platformLocalIndex)) { return(true); } } return(false); } else if (linkedPlatforms.Count > 0) // return false if this scene is linked to a platform but the platform doesn't have any linked scenes { return(false); } // if the platform can't fit, then don't spawn it float totalDistance = ObjectHistory.instance.GetTotalDistance(false); float largestScene = spawnData.largestScene; float sceneBuffer = (spawnData.useWidthBuffer ? platformSceneWidthBuffer : 0); // useWidthBuffer contains the information if we should spawn up to totalDistance if (totalDistance - distance - sceneBuffer - largestScene >= 0) { // largest scene of 0 means we are approaching a turn and it doesn't matter what size object is spawned as long as it fits if (largestScene == 0) { return(totalDistance - distance - sceneBuffer >= zSize); } else { return(largestScene >= zSize); } } return(false); }