void SpawnPlatformStart() { float yPos = startYPos + distBetween; float xPos = 0f; topPlatformYPos = 0; for (int i = 0; i < totalSpawnStart; i++) { xPos = Random.Range(-cameraHalfWidth, cameraHalfWidth); if (platformBins[0].childCount <= 0) { platformGO = Instantiate(platformPrefabs[0], new Vector3(xPos, yPos, 0f), Quaternion.identity) as GameObject; platformGO.transform.SetParent(platformSpawned); Platforme platformScript = platformGO.GetComponent <Platforme> (); GetComponentForPlatformScript(platformScript); } else { platformGO = platformBins[0].GetChild(0).gameObject; platformGO.transform.SetParent(platformSpawned); platformGO.transform.position = new Vector3(xPos, yPos, 0f); } topPlatformYPos = yPos; yPos += distBetween; } }
void SpawnBreakPlatform() { totalBreakPlatformSpawn++; float xPos = Random.Range(-cameraHalfWidth, cameraHalfWidth); if (platformBins[1].childCount <= 0) { platformGO = Instantiate(platformPrefabs[1], new Vector3(xPos - 0.3f, topPlatformYPos, 0f), Quaternion.identity) as GameObject; platformGO.transform.SetParent(platformSpawned); Platforme platformScript = platformGO.GetComponent <Platforme> (); GetComponentForPlatformScript(platformScript); } else { platformGO = platformBins[1].GetChild(0).gameObject; platformGO.transform.position = new Vector3(xPos - 0.3f, topPlatformYPos, 0f); platformGO.transform.SetParent(platformSpawned); } if (platformBins[2].childCount <= 0) { platformGO = Instantiate(platformPrefabs[2], new Vector3(xPos + 0.3f, topPlatformYPos, 0f), Quaternion.identity) as GameObject; platformGO.transform.SetParent(platformSpawned); Platforme platformScript = platformGO.GetComponent <Platforme> (); GetComponentForPlatformScript(platformScript); } else { platformGO = platformBins[2].GetChild(0).gameObject; platformGO.transform.position = new Vector3(xPos + 0.3f, topPlatformYPos, 0f); platformGO.transform.SetParent(platformSpawned); } }
void GetComponentForPlatformScript(Platforme _platformScript) { _platformScript.playerBoxCollider2d = playerBoxCol2d; _platformScript.platformSpawnerScript = this; _platformScript.cameraTrans = cameraScript.gameObject.transform; _platformScript.gameManagerScript = this.gameManagerScript; }
void SpawnNormalPlatform() { if (platformBins[0].childCount <= 0) { platformGO = Instantiate(platformPrefabs[0], new Vector3(Random.Range(-cameraHalfWidth, cameraHalfWidth), topPlatformYPos, 0f), Quaternion.identity) as GameObject; platformGO.transform.SetParent(platformSpawned); Platforme platformScript = platformGO.GetComponent <Platforme> (); GetComponentForPlatformScript(platformScript); } else { platformGO = platformBins[0].GetChild(0).gameObject; platformGO.transform.position = new Vector3(Random.Range(-cameraHalfWidth, cameraHalfWidth), topPlatformYPos, 0f); platformGO.transform.SetParent(platformSpawned); } }