void GenerateGround() { while (SpawnGround()) { _spawnedGround.Add(_groundObjectPool.Instantiate(new Vector3(_curGenerationPos, -2), Quaternion.identity)); _spawnedGround.Add(_grassObjectPool.Instantiate(new Vector3(_curGenerationPos, 0), Quaternion.identity)); _curGenerationPos += tileWidth; } }
void GenerateSpikes() { if (_curGenerationPos < _nextSpikePos) { return; } bool canSpawn = true; if ((int)Random.Range(0, spikeSpawnChance) == 0) { foreach (GameObject g in _staticObsticles) { if (g.tag == "Spikes") { if (g.transform.position.x == _curGenerationPos) { canSpawn = false; Debug.Log("overlap"); break; } } } } else { canSpawn = false; } if (canSpawn) { int groupSize = (int)Random.Range(1, maxGroupSize); for (int i = 0; i < groupSize; i++) { _staticObsticles.Add(_spikeObjectPool.Instantiate(new Vector3(_curGenerationPos + (tileWidth * i), 0), Quaternion.identity)); } _nextSpikePos = _curGenerationPos + (tileWidth * groupSize) + minSpikeSpacing; } }