Procedural Generation Progress

This commit is contained in:
GamerClassN7 2022-01-29 18:30:08 +01:00
parent 7f06907704
commit dd2613e181

View File

@ -11,49 +11,52 @@ public class ProceduralGeneration : MonoBehaviour
private GameObject lastBlock; private GameObject lastBlock;
private GameObject lastBlockPrefab; private GameObject lastBlockPrefab;
private int blockIndex = 0; private int blockIndex = 0;
private int spavnetobjectIndex = 0;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
lastBlockPrefab = this.gameObject.transform.GetChild(0).gameObject; lastBlockPrefab = this.gameObject.transform.GetChild(0).gameObject;
lastBlock = this.gameObject.transform.GetChild(0).gameObject; lastBlock = this.gameObject.transform.GetChild(0).gameObject;
spawnedLevelBlocks.Add(lastBlock); this.spawnedLevelBlocks.Add(lastBlock);
int pieceCount = 10;
float radius = (pieceCount + 1 / 2) * 2;
float angle = 360f / (float)pieceCount;
for (int i = 1; i < pieceCount + 1; i++)
{
Quaternion rotation = (Quaternion.AngleAxis(i * angle, Vector3.back));
Vector3 direction = rotation * Vector3.down;
Vector3 position = (transform.position + (direction * radius)) * (float)(1 + i * 0.05f);
Instantiate(levelBlocks[0], new Vector3(position.x, position.y, position.z), rotation);
}
} }
List<GameObject> drawLoop(GameObject lastObject, GameObject objToSpawn)
{
List<GameObject> levelBlocksSpawnTemp = new List<GameObject>();
Debug.Log("Building LOOP");
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);
for (int i = 1; i < pieceCount + 2; i++)
{
Quaternion rotation = (Quaternion.AngleAxis((i - 1) * angle, Vector3.back));
Vector3 direction = rotation * Vector3.down;
Vector3 position = (lastObject.transform.position + (direction * radius));
levelBlocksSpawnTemp.Add(Instantiate(objToSpawn, new Vector3(position.x, position.y, position.z + (float)(i * 3.0f)), rotation));
}
return levelBlocksSpawnTemp;
}
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
Vector3 playerPosition = this.player.transform.position; Vector3 playerPosition = this.player.transform.position;
float distance = Vector3.Distance(spawnedLevelBlocks[0].transform.position, playerPosition); float distance = Vector3.Distance(this.spawnedLevelBlocks[spavnetobjectIndex].transform.position, playerPosition);
Debug.Log(distance);
if (distance > 10.0f && spawnedLevelBlocks.Count > 10) if (distance > 10.0f && this.spawnedLevelBlocks.Count > 10)
{ {
Destroy(spawnedLevelBlocks[0]); Destroy(this.spawnedLevelBlocks[spavnetobjectIndex]);
spawnedLevelBlocks.Remove(spawnedLevelBlocks[0]); this.spawnedLevelBlocks.Remove(this.spawnedLevelBlocks[spavnetobjectIndex]);
spavnetobjectIndex++;
} }
if (spawnedLevelBlocks.Count <= 10) if (this.spawnedLevelBlocks.Count <= 10)
{ {
MeshFilter meshfilter = lastBlock.GetComponent<MeshFilter>(); MeshFilter meshfilter = lastBlock.GetComponent<MeshFilter>();
Bounds bounds = meshfilter.mesh.bounds; Bounds bounds = meshfilter.mesh.bounds;
@ -61,9 +64,12 @@ public class ProceduralGeneration : MonoBehaviour
float scale = meshfilter.transform.localScale.x; float scale = meshfilter.transform.localScale.x;
Bounds b = new Bounds(bounds.center * scale, bounds.size * scale); Bounds b = new Bounds(bounds.center * scale, bounds.size * scale);
int blockToSpawn = Random.Range(0, levelBlocks.Count); int blockToSpawn = Random.Range(0, levelBlocks.Count - 1);
GameObject blockObjToSpawn = levelBlocks[blockToSpawn]; Debug.Log(blockToSpawn);
GameObject instantiatedGameObject;
GameObject blockObjToSpawn;
blockObjToSpawn = levelBlocks[blockToSpawn];
if (blockObjToSpawn.name == lastBlockPrefab.name) if (blockObjToSpawn.name == lastBlockPrefab.name)
{ {
Debug.Log("Same Block"); Debug.Log("Same Block");
@ -75,16 +81,34 @@ public class ProceduralGeneration : MonoBehaviour
{ {
blockToSpawn--; blockToSpawn--;
} }
blockObjToSpawn = levelBlocks[blockToSpawn];
} }
GameObject instantiatedGameObject = Instantiate(blockObjToSpawn, new Vector3(0, 0, blockIndex * (b.size.z + 1.0f)), (Quaternion.identity)); 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);
blockIndex++;
}
else
{
List<GameObject> instantiatedGameObjectLists = this.drawLoop(lastBlock, levelBlocks[0]);
foreach (var spavnedBlock in instantiatedGameObjectLists)
{
this.spawnedLevelBlocks.Add(spavnedBlock);
blockIndex++;
}
instantiatedGameObject = this.spawnedLevelBlocks[this.spawnedLevelBlocks.Count - 1];
blockObjToSpawn = levelBlocks[0];
}
Debug.Log("Spawn" + blockToSpawn);
lastBlock = instantiatedGameObject; lastBlock = instantiatedGameObject;
spawnedLevelBlocks.Add(lastBlock);
lastBlockPrefab = blockObjToSpawn;
lastBlockSpawnPoint = instantiatedGameObject.transform.position; lastBlockSpawnPoint = instantiatedGameObject.transform.position;
blockIndex++; lastBlockPrefab = blockObjToSpawn;
} }
} }
} }