Ejemplo n.º 1
0
    public GameObject blocksPile;             //a reference to the most recently created bundle of blocks
    public GameObject GenerateBlocks()
    {
        blocksPile = new GameObject();
        blocksPile.transform.SetParent(transform);

        //number this pile appropriately if there are already some piles on it
        int m = 0;

        for (int n = 0; n < transform.childCount; n++)
        {
            if (transform.GetChild(n).name.Contains("pile"))
            {
                m++;
            }
        }
        blocksPile.name = "pile " + (m + 1);

        //convert the spline into a polyLine
        PolyLine polyLine = spline.GetPolyLine(polyLineResolution);

        //spawn the blocks
        for (int i = 0; i < blockCount; i++)
        {
            //get the fraction along the polyline to start at
            float t = (float)i / (blockCount - 1);
            if (endPadding != 0)
            {
                t = Pad(t);
            }

            //get the position that is along the polyline
            Vector3    point = polyLine.GetPoint(t);
            Quaternion orientation;
            if (rotateToCurve)
            {
                Vector3 dir = polyLine.GetDirection(t).Flatten();
                orientation = Quaternion.LookRotation(dir, Vector3.up);
            }
            else
            {
                orientation = Quaternion.identity;
            }

            GameObject go = Instantiate(blockPrefab, point, orientation, blocksPile.transform);
            go.name = "block " + i;
        }

        return(blocksPile);
    }