- Home /
Help with Generating Random Tiles
Hello, So im trying to make a randomly generated dungeon. The way im trying to do it is that i have made 12 different prefabs. Each one is a 3d object. One is a straight path, one is a right turn ect.
And now to my problem. I cant find a efficient way to code this! Heres my script so far,
#pragma strict
var path : Transform[];
var pathType : Transform;
var zSpawnCord : int;
var xSpawnCord : int;
var counter : int;
//Spawn Path
function Update(){
int[] MyLevelsToLoad = new int[] { 2, 3, 6, 9 };
int RandomLevelIndex = (int) Math.Min( MyLevelsToLoad.Length-1, Random.Range( 0, MyLevelsToLoad.Length ) );
//Find What Tile to place
if(counter>1){
//If Previous Tile Has North Oulet
if(path[(counter-1)]==1||
path[(counter-1)]==3||
path[(counter-1)]==5||
path[(counter-1)]==6||
path[(counter-1)]==9||
path[(counter-1)]==11||
path[(counter-1)]==12||
){
pathType = tilesNorthOutlet[Random.Range(0, tilesNorthOutlet.Length)];
}
//Basics of pathmaking
if(xSpawnCord<101){
path[counter] = Instantiate(pathType,Vector3(xSpawnCord,0,zSpawnCord), Quaternion.identity);
counter = (counter + 1);
//Check on adding x
if(zSpawnCord==100){
//Add 1 to X
xSpawnCord = (xSpawnCord + 10);
zSpawnCord = 0;
}
else{
zSpawnCord = (zSpawnCord + 10);
}
}
}
Thanks!!!
Well the question's just "i have these pieces, how do I make them a map?"
In that case, your post (as it appears now) probably isn't appropriate for UnityAnswers. The UnityAnswers philosophy is:
"[Unity Answers] is a place to ask specific questions that have specific answers. The forum is a better place to post discussions and non-technical questions."
As a general rule, posts should probably have the following:
One clear question (what, specifically, are you trying to do?)
Relevant background information (what have you already tried? what other things might be important for us to know?)
Context information (what do you expect to happen? What is happening ins$$anonymous$$d?)
Your request (what specifically do you expect of the UnityAnswers community? Are you looking for links to relevant information, a chunk of code that you can use, ...?)
If your post is one of the following, you should consider changing it or asking on the forums ins$$anonymous$$d:
A one- or couple-sentence post, especially with a broad question ("how do I make a game like Halo?") or no discernible question ("WebPlayer doesn't allow me to save to disk"). We'll need more specific information to help you.
Asking the opinion of the community ("Best method to store files?"). $$anonymous$$uch better to discuss these on the forums.
A question that focuses on the end result, rather than anything technical ("how do I make a laser beam?"). These mean that you probably haven't done enough research. If you're just starting out and don't even know where to look, try searching here, the forums, and Google first and then posting your question to the forums. The Unity resources are a great place to start (http://unity3d.com/support/resources/). When you get to a more technical point ("how do I adjust the color of a line renderer for a laser beam?") we can probably help you.
A disjointed or incomplete question ("How do I make a jumping enemy? Physics doesn't look right."). It will help us if you take a moment to add some context information, background, and general explanation.
Copying your code verbatim with a one-line question like "why doesn't this work?" or "what is wrong with my code?" To the community, this sounds like you came across an error, spent 0 time trying to fix it yourself, and simply posted it in the hope that someone else would do your work for you.
Asking how to make a complete game ("How do I make $$anonymous$$inecraft in Unity?"). Creating a game is a monumental task and not something we can impart to you in 500 words or less.
Finally, make sure that you check to see if your question has already been answered here, and do a quick google search, before posting a new question.
Of course, the members here are awesome folks and will probably try to help you anyway - hopefully you'll get an answer or some helpful comments. If not, now you know why.
Thanks for responding! Im sorry if ive violated the rules of conduct :( i wont do it again.
@Julien : just to say I am in awe of your comment, have pasted a copy to my notepad of generic posts, and I hope you don't $$anonymous$$d if I plagiarize the heck out of it. Well articulated, I have never seen it written better here ever. Simply excellent =]
@$$anonymous$$ileSplit : I thought I'd seen this question somewhere before ....
http://answers.unity3d.com/questions/376501/uhhhh-2d-maze-generator-help.html
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Help with Invisibility script. 1 Answer
random generated room system -1 Answers