Example #1
0
    void CreateWall(Point A, Point B)
    {
        Vector3 Origin;
        float   xCompare = A.x - B.x;
        float   yCompare = A.y - B.y;
        float   Distance = new Vector3(xCompare, yCompare, 0).magnitude;

        //Do a check to see if the walls share a different set of changes.
        //TODO: Need to write a script for diagnonal walls in next update

        if (xCompare == 0)
        {
            Origin = new Vector3(A.x, (A.y + B.y) / 2, A.z);

            //Calculate the origin point
            Origin = new Vector3((A.x + B.x) / 2, A.y, A.z);

            //Create a new wall object
            GameObject wall = Instantiate(_wall, Origin, Quaternion.identity) as GameObject;

            //Fetch the wall's data
            Wall newWall = wall.GetComponent <Wall>();

            //Apply the new wall to both parents
            newWall.AddParents(A, B);
            children.Add(newWall);
            B.children.Add(newWall);

            //Scale the wall to equal the distance between both parents
            //Note that if they are the same X, the distance calculated is between Y.
            newWall.ScaleSelf(new Vector3(1, Distance, 1));
        }

        if (yCompare == 0)
        {
            //Calculate the origin point
            Origin = new Vector3((A.x + B.x) / 2, A.y, A.z);

            //Create a new wall object
            GameObject wall = Instantiate(_wall, Origin, Quaternion.identity) as GameObject;

            //Fetch the wall's data
            Wall newWall = wall.GetComponent <Wall>();

            //Apply the new wall to both parents
            newWall.AddParents(A, B);
            children.Add(newWall);
            B.children.Add(newWall);

            //Scale the wall to equal the distance between both parents
            //Note that if they are the same Y, the distance calculated is between X.
            newWall.ScaleSelf(new Vector3(Distance, 1, 1));
        }

        // Distance = new Vector3(A.x - B.x, A.y - B.y, A.z - B.z);
        // Vector3 Origin = new Vector3(Distance.x/2, Distance.y/2, Distance.z/2);
        //Use Half of Distance to instantiate a new Wall object
        //Use the magnitude to scale the new object
        //Add point B to neighbors and new Wall to children
    }