I made this simple grid / maze script, but how do I spawn the walls rotated 90 degrees? Or do i need to swap the z axis with the y axis? I want the grid to be generated from x to y rather than x to z. If anyone can help, that’d be fantastic!![]()
using UnityEngine;
using System.Collections;
public class MazeScript : MonoBehaviour
{
//THE WALLS
public GameObject wall;
//THE WALLS LENGTH!!
public float wallLength = 1;
//THE SIZE OF THE GRID!!
public int xSize = 5;
public int ySize = 5;
//Our starting position for our grid!
private Vector3 initialPos;
//OTHER MISC SHIZ!!
private GameObject wallHolder;
// Use this for initialization
void Start ()
{
CreateTheWalls ();
}
//This next function will create our walls.
void CreateTheWalls ()
{
wallHolder = new GameObject ();
wallHolder.name = "Maze";
//When the game starts, we want to create the walls in our maze or grid.
{
initialPos = new Vector3((-xSize/2)+wallLength/2.0f,(-ySize/2)+wallLength);
Vector3 myPos = initialPos;
GameObject tempWall;
//for x axis
for (int i = 0; i < ySize; i++)
{
for (int j = 0; j <= xSize; j++)
{
myPos = new Vector3 (initialPos.x + (j*wallLength)-wallLength/2,0.0f,initialPos.z+(i*wallLength)-wallLength/2);
tempWall = Instantiate(wall,myPos,Quaternion.identity) as GameObject;
tempWall.transform.parent = wallHolder.transform;
}
}
//for y axis
for (int i = 0; i <= ySize; i++)
{
for (int j = 0; j < xSize; j++)
{
myPos = new Vector3 (initialPos.x + (j*wallLength),0.0f,initialPos.z+(i*wallLength)-wallLength);
tempWall = Instantiate(wall,myPos,Quaternion.Euler(0.0f,90.0f,0.0f)) as GameObject;
tempWall.transform.parent = wallHolder.transform;
}
}
}
}
}