Example #1
0
    void Start()
    {
        rng    = new System.Random();
        parent = GameObject.Find("WallManagerGO");

        //------------------------------------------//
        //-------------Wall generation--------------//
        //------------------------------------------//

        WallArray = new GameObject[mazeSize][];
        wallState = new float[mazeSize][];
        for (int i = 0; i < mazeSize; i++)
        {
            WallArray[i] = new GameObject[mazeSize];
            wallState[i] = new float[mazeSize];

            for (int j = 0; j < mazeSize; j++)
            {
                WallArray[i][j] = (GameObject)Object.Instantiate
                                      (WallGO, new Vector3(i * wallSize, wallSize / 2, j * wallSize), Quaternion.identity);
                WallArray[i][j].transform.parent = parent.transform;         //sets the GO neatly in heiarchy.


                //Editing the script component
                WallScript currentWall = WallArray[i][j].GetComponent <WallScript>();
                currentWall.Setup(i, j, -wallSize / 2, wallSize / 2); //gives the wall info about itself, like its location, max/min height.
                currentWall.SetParent(WallArray[i][j]);               // lets the object know about itself.
                currentWall.SetHeight(1);                             //All walls start raised.
                wallState[i][j] = 1;                                  // keep track of the value in wallState.
                currentWall.SetSize(wallSize);                        // sets the cube's size.
            }
        }


        //---------------------------------------//
        //-------------Outside Walls-------------//
        //---------------------------------------//

        //GameObject floor = GameObject.CreatePrimitive(PrimitiveType.Cube);
        GameObject zMaxWall = GameObject.CreatePrimitive(PrimitiveType.Cube);
        GameObject zMinWall = GameObject.CreatePrimitive(PrimitiveType.Cube);
        GameObject xMaxWall = GameObject.CreatePrimitive(PrimitiveType.Cube);
        GameObject xMinWall = GameObject.CreatePrimitive(PrimitiveType.Cube);

        float fullDist       = (mazeSize * wallSize);
        float halfDist       = (fullDist) / 2;
        float permWallHeight = wallSize * 2;

        //floor - Might not even be necessary? - Wait yes it is. - WAIT NO ITS NOT.

        /*
         * floor.transform.position = new Vector3(halfDist,-.5f,halfDist);
         * floor.transform.localScale = new Vector3(fullDist,1,fullDist);
         */

        //other walls - should be working!
        zMaxWall.transform.position   = new Vector3(halfDist, permWallHeight / 2, fullDist);
        zMaxWall.transform.localScale = new Vector3(fullDist + wallSize, permWallHeight, wallSize);
        zMaxWall.name = "zMaxWall";
        zMaxWall.renderer.material.SetTexture("_MainTex", wallTexture);
        zMaxWall.renderer.material.mainTextureScale = new Vector2(mazeSize, 2);

        zMinWall.transform.position   = new Vector3(halfDist, permWallHeight / 2, -wallSize);
        zMinWall.transform.localScale = new Vector3(fullDist + wallSize, permWallHeight, wallSize);
        zMinWall.name = "zMinWall";
        zMinWall.renderer.material.SetTexture("_MainTex", wallTexture);
        zMinWall.renderer.material.mainTextureScale = new Vector2(mazeSize, 2);

        xMaxWall.transform.position   = new Vector3(fullDist, permWallHeight / 2, halfDist);
        xMaxWall.transform.localScale = new Vector3(wallSize, permWallHeight, fullDist + wallSize);
        xMaxWall.name = "xMaxWall";
        xMaxWall.renderer.material.SetTexture("_MainTex", wallTexture);
        xMaxWall.renderer.material.mainTextureScale = new Vector2(mazeSize, 2);


        xMinWall.transform.position   = new Vector3(-wallSize, permWallHeight / 2, halfDist);
        xMinWall.transform.localScale = new Vector3(wallSize, permWallHeight, fullDist + wallSize);
        xMinWall.name = "xMinWall";
        xMinWall.renderer.material.SetTexture("_MainTex", wallTexture);
        xMinWall.renderer.material.mainTextureScale = new Vector2(mazeSize, 2);

        //---------------------------------------//
        //----------------Towers-----------------//
        //---------------------------------------//

        float wallAdjustment = 2.0f;

        Object.Instantiate(RedTorch, new Vector3(fullDist, permWallHeight + wallAdjustment, fullDist), Quaternion.identity);
        Object.Instantiate(YellowTorch, new Vector3(fullDist, permWallHeight + wallAdjustment, -wallSize), Quaternion.identity);
        Object.Instantiate(GreenTorch, new Vector3(-wallSize, permWallHeight + wallAdjustment, fullDist), Quaternion.identity);
        Object.Instantiate(BlueTorch, new Vector3(-wallSize, permWallHeight + wallAdjustment, -wallSize), Quaternion.identity);
    }