Hi,
I am trying to write a procedural level generation script which contains 5 different shaped sections which are placed into a public Transform array (Sections dragged into slots in Inspector, etc.) Each section has its pivot at one end (the front) and an object with tag ‘helper’ at the other end (this is the End-point of each section). The script looks through each section to find its ‘helper’ object (End-point) and then assigns this to the next Transform (Section) in the array (therefore, to its Start-point).
What I would like to be able to do now is to have say one starting section already in the scene, and then have the others generate after it in random order one after the other.
Any help with this would be greatly appreciated!
The following function is my starting point. It receives a random number (ChosenIndex) and then goes onto select the section corresponding to that index. It will first create a new Transform (nextTrans) to the chosen section and then assign its position and rotation accordingly. This depends on whether we are adding onto the first (already existing) section in the scene, or ones we have added using the script.
However, running this seems to add the new section at the Start of the existing section (ie. on top) in the scene, not at its end-point. Having looked at the new section when the scene is running, it seems that its y-rotation is at 180 degrees, I’m not sure why this is the case.
Note,
-
ParkLotSectionList - the list of sections in the Parking Lot/available to add in the scene (added via Inspector)
-
EndpointPositionsList - the list of End-points of the sections in the Parking Lot, corresponding with their index (0 - 4) - (added via Inspector)
-
StartingSectionEndpoint - the End-point of the existing section in the scene (added via Inspector)
-
firstSection - simply a boolean to check which starting point to use
Thanks in advance.
//----
void SectionSelector (int ChosenIndex)
{
// Assign the chosen section to a new Transform, nextTrans
Transform nextTrans = ParkLotSectionList[ChosenIndex];
// Adding into the first section in the scene
if (firstSection)
{
nextTrans.position = StartingSectionEndpoint.position;
nextTrans.rotation = StartingSectionEndpoint.rotation;
Debug.Log("nextTrans.position = " + nextTrans.position);
firstSection = false;
}
// Otherwise, assign it the End-point values for the following sections
else
{
nextTrans.position = EndpointPositionsList[ChosenIndex].position;
nextTrans.rotation = EndpointPositionsList[ChosenIndex].rotation;
}
}