- Home /
Array based floor 3D game flat plane
Hey guys, I'm making a game and would like to have a tile texture based floor.
I have absolutely no idea, I hear a lot of people throwing around the idea of using an array but I have no idea how to get my array of [tile1,til2,tile3] w/e to placing the literal textures in the game.
here's a gif of what my game is like visually I suppose http://imgur.com/kbdoR3L
Any direction to a tutorial that will help with what I want would be great as I don't expect to get a whole lot of code haha! But I generally just want to be able to change between like grass, dirt, stone, road textures.
Thanks a lot guys! Love the community here.
Instantiate(myObjectArray[0], someVector3,SomeQuaternion); you can put whatever object you want to instantiate in and make the vecotr3 the place you want it instantiated and the quaternion is the objects rotation.
hope this helps! http://docs.unity3d.com/ScriptReference/Object.Instantiate.html
Answer by jmgek · Jun 03, 2015 at 05:15 AM
//Create a List or array, I like lists they are more dynamic.
public List<GameObject> listOfTiles = new List<GameObject>();
//Create how large you want your map to be.
private int numberOfTiles = 10;
//Create an int that you want to use to spawn the tiles.
private int currentTileYouAreSpawning = 0;
private void Start()
{
for (int x = 0; x < length; x++)
{
for (int z = 0; z < length; z++)
{
Instantiate(listOfTiles[currentTileYouAreSpawning], new Vector3(x, 0, z), Quaternion.identity);
}
}
}
With this list approch you will learn how to spawn random tiles if you wanted to. This is just the most basic of generation but it will lead you to some really cool things.
Your answer
Follow this Question
Related Questions
PackTextures Horizontally? (1 Row) or Alternative Method 1 Answer
Making an array for Texture2D?? 2 Answers
Accessing a Variable From Another Script 2 Answers
2D Sprites Rendering Inconsistently Between Computers 0 Answers
RawImage flicker when changing from Texture2D to VideoPlayer texture 1 Answer