From 5f2532576b2bc5cb7d3614c10c11fe440f1d505f Mon Sep 17 00:00:00 2001 From: GamerClassN7 Date: Sat, 29 Jan 2022 18:57:24 +0100 Subject: [PATCH] Tweaks --- Assets/Scripts/ProceduralGeneration.cs | 29 +++++++++++++++++++------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/ProceduralGeneration.cs b/Assets/Scripts/ProceduralGeneration.cs index 52070d4..13b17ab 100644 --- a/Assets/Scripts/ProceduralGeneration.cs +++ b/Assets/Scripts/ProceduralGeneration.cs @@ -5,10 +5,10 @@ using UnityEngine; public class ProceduralGeneration : MonoBehaviour { public List levelBlocks = new List(); - private List spawnedLevelBlocks = new List(); + public List spawnedLevelBlocks = new List(); public GameObject player = null; private Vector3 lastBlockSpawnPoint; - private GameObject lastBlock; + public GameObject lastBlock; private GameObject lastBlockPrefab; private int blockIndex = 0; private int spavnetobjectIndex = 0; @@ -34,7 +34,7 @@ public class ProceduralGeneration : MonoBehaviour int pieceCount = 10; float radius = (pieceCount / 2) * 2; float angle = 360f / (float)pieceCount; - Vector3 centerPoint = new Vector3(lastObject.transform.position.x, (lastObject.transform.position.y), lastObject.transform.position.z); + Vector3 centerPoint = new Vector3(lastObject.transform.position.x, (lastObject.transform.position.y + radius), lastObject.transform.position.z); for (int i = 1; i < pieceCount + 2; i++) { @@ -52,12 +52,14 @@ public class ProceduralGeneration : MonoBehaviour void Update() { Vector3 playerPosition = this.player.transform.position; - float distance = Vector3.Distance(this.spawnedLevelBlocks[spavnetobjectIndex].transform.position, playerPosition); + float distance = Vector3.Distance(this.spawnedLevelBlocks[0].transform.position, playerPosition); + + Debug.Log("Index" + 0); if (distance > 10.0f && this.spawnedLevelBlocks.Count > 10) { - Destroy(this.spawnedLevelBlocks[spavnetobjectIndex]); - this.spawnedLevelBlocks.Remove(this.spawnedLevelBlocks[spavnetobjectIndex]); + Destroy(this.spawnedLevelBlocks[0]); + this.spawnedLevelBlocks.Remove(this.spawnedLevelBlocks[0]); spavnetobjectIndex++; } @@ -70,7 +72,9 @@ public class ProceduralGeneration : MonoBehaviour Bounds b = new Bounds(bounds.center * scale, bounds.size * scale); int blockToSpawn = Random.Range(0, levelBlocks.Count - 1); + Debug.Log(blockToSpawn); + GameObject instantiatedGameObject; GameObject blockObjToSpawn; @@ -86,13 +90,21 @@ public class ProceduralGeneration : MonoBehaviour { blockToSpawn--; } + if ((blockToSpawn + 1) <= levelBlocks.Count) + { + blockToSpawn++; + } + else if ((blockToSpawn - 1) >= levelBlocks.Count) + { + blockToSpawn--; + } } if ((blockToSpawn > -1 && (blockToSpawn < (levelBlocks.Count - 1)))) { blockObjToSpawn = levelBlocks[blockToSpawn]; instantiatedGameObject = Instantiate(blockObjToSpawn, new Vector3(0, 0, blockIndex * (b.size.z + 1.0f)), (Quaternion.identity)); - this.spawnedLevelBlocks.Add(lastBlock); + this.spawnedLevelBlocks.Add(instantiatedGameObject); blockIndex++; } else @@ -110,10 +122,11 @@ public class ProceduralGeneration : MonoBehaviour Debug.Log("Spawn" + blockToSpawn); + lastBlock = instantiatedGameObject; lastBlockSpawnPoint = instantiatedGameObject.transform.position; lastBlockPrefab = blockObjToSpawn; - } } } +