diff --git a/Assets/Scenes/Vasek.unity b/Assets/Scenes/Vasek.unity index 1518463..7abba2c 100644 --- a/Assets/Scenes/Vasek.unity +++ b/Assets/Scenes/Vasek.unity @@ -123,6 +123,11 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1 &250075900 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 3244356566819001084, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} + m_PrefabInstance: {fileID: 1287430439} + m_PrefabAsset: {fileID: 0} --- !u!1 &327689120 GameObject: m_ObjectHideFlags: 0 @@ -154,7 +159,7 @@ Transform: m_Children: - {fileID: 708734976} m_Father: {fileID: 0} - m_RootOrder: 0 + m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &327689122 MonoBehaviour: @@ -173,7 +178,7 @@ MonoBehaviour: - {fileID: 8768991388683709947, guid: 99c4e582c7358f346ab00dae4ae956f9, type: 3} - {fileID: 6650340373999088090, guid: 76b3e3235b07ca04f91c9b020603e1dd, type: 3} spawnedLevelBlocks: [] - player: {fileID: 1621231496} + player: {fileID: 250075900} lastBlock: {fileID: 708734972} --- !u!1 &705507993 GameObject: @@ -366,11 +371,63 @@ Transform: m_Father: {fileID: 327689121} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &1621231496 stripped -GameObject: - m_CorrespondingSourceObject: {fileID: 3244356566819001084, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} - m_PrefabInstance: {fileID: 1953646381} - m_PrefabAsset: {fileID: 0} +--- !u!1001 &1287430439 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 3244356567786994344, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} + propertyPath: m_Name + value: Player + objectReference: {fileID: 0} + - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} + propertyPath: m_RootOrder + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} + propertyPath: m_LocalPosition.y + value: 1.95 + objectReference: {fileID: 0} + - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} + propertyPath: m_LocalRotation.x + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} + propertyPath: m_LocalRotation.y + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} + propertyPath: m_LocalRotation.z + value: -0 + objectReference: {fileID: 0} + - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} --- !u!1 &1802677907 GameObject: m_ObjectHideFlags: 0 @@ -420,64 +477,3 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1001 &1953646381 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 3244356566819001085, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} - propertyPath: m_LocalPosition.z - value: 0.7 - objectReference: {fileID: 0} - - target: {fileID: 3244356567786994344, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} - propertyPath: m_Name - value: Player - objectReference: {fileID: 0} - - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} - propertyPath: m_RootOrder - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} - propertyPath: m_LocalPosition.x - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3244356567786994345, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: ec622cf6f0988bc42a99ba84304c15a9, type: 3} diff --git a/Assets/Scripts/ProceduralGeneration.cs b/Assets/Scripts/ProceduralGeneration.cs index e97417e..aee77a2 100644 --- a/Assets/Scripts/ProceduralGeneration.cs +++ b/Assets/Scripts/ProceduralGeneration.cs @@ -30,7 +30,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 + radius), lastObject.transform.position.z + 2.0f); + Vector3 centerPoint = new Vector3(lastObject.transform.position.x, (lastObject.transform.position.y + radius), lastObject.transform.position.z + 3.0f); float heightOffset = radius; @@ -49,28 +49,30 @@ public class ProceduralGeneration : MonoBehaviour // Update is called once per frame void Update() { - int maxNumberOfBlock = 100; + int maxNumberOfBlock = 200; Vector3 playerPosition = this.player.transform.position; - float distance = Vector3.Distance(this.spawnedLevelBlocks[0].transform.position, playerPosition); Debug.Log("Index" + 0); - if (distance > 10.0f || this.spawnedLevelBlocks.Count >= maxNumberOfBlock + 5) + for (var i = 0; i < this.spawnedLevelBlocks.Count; i++) { - Destroy(this.spawnedLevelBlocks[0]); - this.spawnedLevelBlocks.Remove(this.spawnedLevelBlocks[0]); - spavnetobjectIndex++; + float distance = Vector3.Distance(this.spawnedLevelBlocks[i].transform.position, playerPosition); + if (distance > 10.0f && this.spawnedLevelBlocks.Count >= maxNumberOfBlock) + { + Destroy(this.spawnedLevelBlocks[i]); + this.spawnedLevelBlocks.Remove(this.spawnedLevelBlocks[i]); + spavnetobjectIndex++; + } + else + { + break; + } } + if (this.spawnedLevelBlocks.Count <= maxNumberOfBlock) { - MeshFilter meshfilter = lastBlock.GetComponent(); - Bounds bounds = meshfilter.mesh.bounds; - - float scale = meshfilter.transform.localScale.x; - Bounds b = new Bounds(bounds.center * scale, bounds.size * scale); - int blockToSpawn = Random.Range(0, levelBlocks.Count - 1); GameObject instantiatedGameObject; @@ -100,9 +102,17 @@ public class ProceduralGeneration : MonoBehaviour if ((blockToSpawn > -1 && (blockToSpawn < (levelBlocks.Count - 1)))) { + MeshFilter meshfilter = this.lastBlock.GetComponent(); + Bounds bounds = meshfilter.mesh.bounds; + + float scale = meshfilter.transform.localScale.x; + Bounds b = new Bounds(bounds.center * scale, bounds.size * scale); + blockObjToSpawn = levelBlocks[blockToSpawn]; - instantiatedGameObject = Instantiate(blockObjToSpawn, new Vector3(lastBlock.transform.position.x, lastBlock.transform.position.y, lastBlock.transform.position.y + (b.size.z + 1.0f)), (Quaternion.identity)); + Vector3 nextBlockLocation = new Vector3(this.lastBlock.transform.position.x, this.lastBlock.transform.position.y, this.lastBlock.transform.position.z + b.size.z + 1.0f); + instantiatedGameObject = Instantiate(blockObjToSpawn, nextBlockLocation, (Quaternion.identity)); this.spawnedLevelBlocks.Add(instantiatedGameObject); + } else { @@ -116,9 +126,9 @@ public class ProceduralGeneration : MonoBehaviour } Debug.Log("Spawn" + blockToSpawn); + this.lastBlock = instantiatedGameObject; + this.lastBlockPrefab = blockObjToSpawn; - lastBlock = instantiatedGameObject; - lastBlockPrefab = blockObjToSpawn; } } }