// Update is called once per frame void Update() { if (transform.position.x < generationPoint.position.x) { //Random Number between distanceMin & distanceMax distanceBetween = Random.Range(distanceMin, distanceMax); platformSelector = Random.Range(0, reusePlatforms.Length); heightChange = transform.position.y + Random.Range(maxChange, -maxChange); if (heightChange > maxHeight) //keeping the platforms in the screen { heightChange = maxHeight; } else if (heightChange < minHeight) { heightChange = minHeight; } //get the new Position for the GenerationPoint transform.position = new Vector3(transform.position.x + (platformWidths[platformSelector] / 2) + distanceBetween, heightChange, transform.position.z); GameObject newPlatform = reusePlatforms[platformSelector].GetReuseablePlatform(); //get a platform that is inactive and reuse it newPlatform.transform.position = transform.position; //add current position to that platform newPlatform.transform.rotation = transform.rotation; //because it was instantiated without rotation newPlatform.SetActive(true); //make the platform visible now if (Random.Range(0f, 10f) < randomCoinThreshold) { myCoinGenerator.GenerateCoins(new Vector3(transform.position.x, transform.position.y + 1f, 20)); } //Generation point gets put in front of the platform transform.position = new Vector3(transform.position.x + (platformWidths[platformSelector] / 2), transform.position.y, transform.position.z); } }
public void GenerateCoins(RoadSegements segement) { coinGenerator.GenerateCoins(segement); }