/** * Instantiate the new platform of the level */ protected virtual void SpawnPlatform(int platformWidth, int platformHeight) { player.GetComponent <PlayerController>().SetData(lastPlatformCreated.name); int n = 1; bool firstPlatformsSpawn = lastPlatformCreated.Equals(firstPlatforms); if (firstPlatformsSpawn) { n = TrapGap(); } else { platformName = lastPlatformCreated.name; lastType = lastPlatformCreated.GetComponent <PrefabController>().myType; } for (int i = 0; i < n; i++) { transform.position = new Vector3(transform.position.x + platformWidth, transform.position.y + platformHeight, transform.position.z); Instantiate(lastPlatformCreated, transform.position, transform.rotation); heightLevel = heightLevel + platformHeight; SpawnBackgroundBlocks(platformWidth, platformHeight); if (firstPlatformsSpawn) { SpawnElement(); } } }
private string GetID(TypeOfPlatform platform, TypeOfID idType) { string id = ""; for (int i = 0; i < ids.Length; i++) { if (ids[i].platform == platform) { if (ids[i].idType == idType) { id = ids[i].id; break; } } } return(id); }
/** * Select the next platform depending of the part of the body */ public void SelectPlatformBody(TypeOfPlatform platformType) { if (platformType == TypeOfPlatform.neutral) { return; } List <GameObject> platformBody = new List <GameObject>(); List <int> weights = new List <int>(); int selector; for (int i = 0; i < platformsList.Length; i++) { if (platformsList[i].GetComponent <PrefabController>().myType == platformType) { platformBody.Add(platformsList[i]); weights.Add(platformsList[i].GetComponent <PrefabController>().Weight); } } selector = RandomSpawn(weights); DepthFirstSearch(firstPlatforms, platformBody[selector]); }