private void Awake() { chunkGenerator.GenerateChunkAt(new Vector2(0, 0)); // generate a new chunk at the center (testing purposes only) waitTime = new WaitForSeconds(chunkUpdateDelay); // create the wait time player = FindObjectOfType <Player>(); // get the player object StartCoroutine(UpdateChunks()); // start updating chunks }
// floats telling us where the player was last, used to help performance private void Awake() { chunkGenerator.GenerateChunkAt(new Vector2(25.5f, 25.5f)); chunkGenerator.GenerateChunkAt(new Vector2(-24.5f, 25.5f)); chunkGenerator.GenerateChunkAt(new Vector2(-24.5f, -24.5f)); chunkGenerator.GenerateChunkAt(new Vector2(25.5f, -24.5f)); waitTime = new WaitForSeconds(chunkUpdateDelay); // create the wait time player = FindObjectOfType <Player>(); // get the player object StartCoroutine(UpdateChunks()); // start updating chunks }
// floats telling us where the player was last, used to help performance private void Awake() { chunkGenerator.GenerateChunkAt(new Vector2(25.5f, 25.5f)); chunkGenerator.GenerateChunkAt(new Vector2(-24.5f, 25.5f)); chunkGenerator.GenerateChunkAt(new Vector2(-24.5f, -24.5f)); chunkGenerator.GenerateChunkAt(new Vector2(25.5f, -24.5f)); // generate chunks in a square around the player. use .5 so that player is aligned with the center rather than at the side waitTime = new WaitForSeconds(chunkUpdateDelay); // create the wait time player = FindObjectOfType <Player>(); // get the player object StartCoroutine(UpdateChunks()); // start updating chunks }
// inherit from editor public override void OnInspectorGUI() { // override method for when the inspector's gui is opened ChunkGenerator mapGen = (ChunkGenerator)target; // create mapgen, target is the object that is being inspected and we want to cast it to be a mapgenerator if (DrawDefaultInspector()) { // draw the default inspector (if any value was changed) if (mapGen.autoUpdate) { mapGen.GenerateChunkAt(mapGen.center, true); // mapGen.ChunkTest(mapGen.center); } } if (GUILayout.Button("Generate")) { // if player clicked the "generate" button mapGen.GenerateChunkAt(mapGen.center, true); // generate the map // mapGen.ChunkTest(mapGen.center); } }
private IEnumerator GenerateArtifactCoroutine(int increment) { if (chunkGenerator.centerChunk != null) { Vector2 testPosition = new Vector2(chunkGenerator.centerChunk.transform.position.x + chunkGenerator.chunkSize * Random.Range(-maxChunksForGeneration - increment, maxChunksForGeneration + 1 + increment), chunkGenerator.centerChunk.transform.position.y + chunkGenerator.chunkSize * Random.Range(-maxChunksForGeneration - increment, maxChunksForGeneration + 1 + increment)); // get a chunk within a set x y chunk limit of the player's position if (!chunkGenerator.chunkPositions.Contains(testPosition)) { // if the chunk hasn't already been generated GameObject newChunk = chunkGenerator.GenerateChunkAt(testPosition); // generate it if (LandExistsIn(newChunk)) { float[] foundCoords = GetMaxHeightOfChunk(newChunk); // spawn artifact based on text position + foundcoords; GameObject createdArtifact = Instantiate(artifactPrefab, new Vector2( testPosition.x - 25 + foundCoords[0], testPosition.y - 25 + foundCoords[1]), Quaternion.identity); createdArtifact.GetComponent <Artifact>().artifactNum = Random.Range(0, 4); createdArtifact.GetComponent <SpriteRenderer>().sprite = artifactSprites[createdArtifact.GetComponent <Artifact>().artifactNum]; FindObjectOfType <Minimap>().CreateArtifactOnMinimap(createdArtifact); } else { chunkGenerator.chunks.Remove(newChunk); chunkGenerator.chunkPositions.Remove(testPosition); // remove the chunk from the arrays its data was added to Destroy(newChunk); // destroy it yield return(waitTime); GenerateArtifact(increment); } } else { yield return(waitTime); GenerateArtifact(increment + 2); } } else { yield return(waitTime); GenerateArtifact(increment); } }