Automatically add platform area tile as player approaches the edge of current tile
Firstly, I'm new to Unity and I'm currently learning c#, please be gentle!
As a project, I'd like to create a simple 3d platform game. The idea being the player starts on a square tile, which is the game platform playing area. They explore different elements on this tile by moving around.
The perspective is 3rd person, so the player is looking down on the action. As they approach the edge of the tile Unity recognises this and adds another tile to the existing one, basically doubling the playing area.
As the player moves around further to the tiles edge, other tiles are added, increasing the discovered areas each time.
My thinking to achieve this would be to have 5 tile game objects, that have different elements like trees already built on them. The question is what is the best way to achieve this.
Would it be to build the complete level with all tiles and then using code restrict how far ahead the player can see, basically to the width and length of the tiles.
Or would it be better to trigger a new tile to appear as the player approaches the edge of the current tile.
Thought, links to example code that I could recycle would be very handy.
Thank you.
Answer by nickcooper · Feb 25, 2017 at 02:06 PM
I would suggest instantiating all your tiles for the map (depending on how large the dimensions) and then setting all of the non visible tile objects/prefabs to inactive. I'm assuming you are using a square grid. I then base the visibility of your tiles on how close they are to your player. It would likely be more efficient to check neighboring tiles based on the tile the player occupies. This is actually similar to how minecraft loads its chunks.
Your answer
Follow this Question
Related Questions
#if UNITY_ANDROID doesn't exists in unity 5 3 Answers
Making a level for a 2D platform Racing game? 0 Answers
transform.childCount not working as intended 0 Answers
How to pass in an Integer 1 Answer