public void SpawnCoins(Vector3 startPosition) { GameObject coin1 = coinPool.GetPooledObject(); coin1.transform.position = startPosition; coin1.SetActive(true); GameObject coin2 = coinPool.GetPooledObject(); coin2.transform.position = new Vector3(startPosition.x - distanceBeyweenCoin, startPosition.y, startPosition.z); coin2.SetActive(true); GameObject coin3 = coinPool.GetPooledObject(); coin3.transform.position = new Vector3(startPosition.x + distanceBeyweenCoin, startPosition.y, startPosition.z); coin3.SetActive(true); }
// Update is called once per frame void Update() { if (transform.position.x < generationPoint.position.x) { distanceBetween = Random.Range(distanceBetweenMin, distanceBetweenMax); platformSelector = Random.Range(0, theObjectPools.Length); heightChange = transform.position.y + Random.Range(maxHeightChange, -maxHeightChange); if (heightChange > maxHeight || heightChange < minHeight) { heightChange = maxHeight; } else if (heightChange < minHeight) { heightChange = minHeight; } if (Random.Range(0f, 100f) < powerupThreshold) { GameObject newPowerUp = powerupPool.GetPooledObject(); newPowerUp.transform.position = transform.position + new Vector3(distanceBetween / 2f, Random.Range(powerupHeight / 2f, powerupHeight), 0f); newPowerUp.SetActive(true); } transform.position = new Vector3(transform.position.x + (platFormWidths[platformSelector] / 2) + distanceBetween, heightChange, transform.position.z); //Instantiate (/*thePlatform*/thePlatforms[platformSelector], transform.position, transform.rotation); GameObject newPlatform = theObjectPools[platformSelector].GetPooledObject(); newPlatform.transform.position = transform.position; newPlatform.transform.rotation = transform.rotation; newPlatform.SetActive(true); if (Random.Range(0f, 100f) < randomCoinThreshold) { theCoinGenerator.SpawnCoins(new Vector3(transform.position.x, transform.position.y + 1f, transform.position.z)); } if (Random.Range(0f, 100f) < randomSpikeThreshold) { GameObject newSpike = spikePool.GetPooledObject(); float spikeXposition = Random.Range(-platFormWidths[platformSelector] / 2f + 1f, platFormWidths[platformSelector] / 2f - 1f); Vector3 spikePosition = new Vector3(spikeXposition, 0.5f, 0f); newSpike.transform.position = transform.position + spikePosition; newSpike.transform.rotation = transform.rotation; newSpike.SetActive(true); } transform.position = new Vector3(transform.position.x + (platFormWidths[platformSelector] / 2), transform.position.y, transform.position.z); } }