Alright so in my code I’m attempting to have the code select a random number of rooms between 7 and 12 for the current floor, pick a layout from an array list with that many rooms, then gather all the spawnpoints and place them in an array called spawnPoints. This works and when the code is run the result shows up with the Debug.Log of “Room #A|X:B|Y:C” but the second Debug.Log only returns (0,0,0) once and then the code just skips this Debug.Log for the rest of the length of the spawnPoints array. Is this returning the location of the array and not properly separating the spawnpoint objects and gathering their individual cell locations? How would I change my code to do that?
public class GenerationManager : MonoBehaviour
{
public int roomCount, selectedGrid;
public GameObject spawnPoints;
[SerializeField]
public Tilemap Gen7, Gen8, Gen9, Gen10, Gen11, Gen12;
public Tilemap floorPlan;
public Grid grid;
public Vector3Int tilePos;
public Tile tile;
// Start is called before the first frame update
void Start()
{
//generate number of rooms that will be on current floor
roomCount = Random.Range(7, 13);
//depending on number, generates an id to search for in an array assigned to an equal number of rooms
//and sets a room matching the id to the current floor plan
switch (roomCount)
{
case 7:
selectedGrid = Random.Range(0, Gen7.Length);
floorPlan = Gen7[selectedGrid];
break;
case 8:
selectedGrid = Random.Range(0, Gen8.Length);
floorPlan = Gen8[selectedGrid];
break;
case 9:
selectedGrid = Random.Range(0, Gen9.Length);
floorPlan = Gen9[selectedGrid];
break;
case 10:
selectedGrid = Random.Range(0, Gen10.Length);
floorPlan = Gen10[selectedGrid];
break;
case 11:
selectedGrid = Random.Range(0, Gen11.Length);
floorPlan = Gen11[selectedGrid];
break;
case 12:
selectedGrid = Random.Range(0, Gen12.Length);
floorPlan = Gen12[selectedGrid];
break;
}
//creates tilemap with rooms in scene
Instantiate(floorPlan, grid.transform);
//scans for all room spawnpoints
spawnPoints = GameObject.FindGameObjectsWithTag("RoomSpawnPoint");
//proves it's caught all the rooms
for(int i=0; i < spawnPoints.Length; i++)
{
Debug.Log("Room #" + i + " | X:" + spawnPoints_.transform.position.x + " | Y:" + spawnPoints*.transform.position.y);*_
Debug.Log(floorPlan.LocalToCell(spawnPoints*.transform.position));*
}
}
}