- Home /
why does my code tag objects it's not supposed to?
I'm trying to randomly generate a dungeon based on predefined rooms. Every time a new room is created, it is supposed to remove the "Endpoint" tag, so that room will not be included in the next search for a liable room. Each of these rooms has a child, endPoint, from which the next room will be built on. each endPoint is tagged "Endpoint" like in the code. The code -does- "Untag" the objects like it's supposed to, but for some reason or another it will ocassionally "Untag" the newly created room, resulting in a random dungeon sometimes from 4 - 6 rooms long.
function Update () {
timer++;
if (timer >= 60)
{
timer = 0;
MakeDungeon();
}
}
function MakeDungeon()
{
endPoints = GameObject.FindGameObjectsWithTag("Endpoint");
// picks a random rooms endpoint.
var randomPoint:GameObject = endPoints[Random.Range(0,endPoints.length)];
//var room: Transform = randomPoint.transform.parent;
Instantiate(verticalHall,randomPoint.transform.position,Quaternion.identity);
randomPoint.gameObject.tag = "Untagged";
}
Your answer
Follow this Question
Related Questions
instantiate a random object from multiples via 'tag' 1 Answer
How do you get different random numbers for each object array? 1 Answer
Getting the Tag Array 2 Answers
Randomize Audio Clip 1 Answer
Question about arrays. 1 Answer