示例#1
0
    //returns the rotation of tunnelPiece
    private Quaternion RotationOfTunnel(TunnelPieces rotateAroundZOfTunnelPiece)
    {
        Vector3 tempRotation = rotateAroundZOfTunnelPiece.endPoint.eulerAngles;

        tempRotation.z = Random.Range(0, 360);
        return(Quaternion.Euler(tempRotation));
    }
示例#2
0
    private void Start()
    {
        tunnelPool = GetComponent <TunnelPooling>();

        tunnelPieces[arrayIndex] = Instantiate(startTunnelPrefab, startOrigin, startTunnelPrefab.transform.rotation);
        currentObject            = tunnelPieces[arrayIndex].GetComponent <TunnelPieces>();
        boxGridGenerator.SetUpBoxGrid(currentObject, ref boxGrid);

        SpawnOnTrigger.generator = GetComponent <TunnelGenarator>();
        for (int i = 1; i < numberOfTunnelObjects; i++)
        {
            GenerateNewTunnelPiece(i, false);
        }
    }
示例#3
0
    //Instantiate new tunnelPices
    private void TunnelPieceInstatiation(int arrayIndex)
    {
        //int randomNumber = Randomizer(tunnelPrefabs.Length);
        GameObject temp = tunnelPool.GetNextObject(tunnelPieces);

        //Destroy(tunnelPieces[arrayIndex]);
        if (tunnelPieces[arrayIndex] != null)
        {
            tunnelPieces[arrayIndex].gameObject.SetActive(false);
        }
        tunnelPieces[arrayIndex] = null;

        previousObject = (arrayIndex != 0) ? previousObject : tunnelPieces[numberOfTunnelObjects - 1].GetComponent <TunnelPieces>();
        //tunnelPieces[arrayIndex] = Instantiate(tunnelPrefabs[randomNumber], previousObject.endPoint.position, RotationOfTunnel(previousObject));
        tunnelPieces[arrayIndex] = temp;
        temp.transform.position  = previousObject.endPoint.position;
        temp.transform.rotation  = RotationOfTunnel(previousObject);
        temp.SetActive(true);
        currentObject = tunnelPieces[arrayIndex].GetComponent <TunnelPieces>();
        currentObject.midPoint.gameObject.SetActive(true);
    }
示例#4
0
    //Checks if there are any mid points set up in the object and calles generateBoxGrid.
    internal void SetUpBoxGrid(TunnelPieces currentObject, ref List <BoxGrid> boxGrid)
    {
        List <Transform> midPoints = GetChildrenWithTag(currentObject.transform, "midPoint");

        if (midPoints.Count != 0)
        {
            GenerateBoxGrid(currentObject.startPoint, midPoints[0], ref boxGrid);

            for (int i = 0; i < midPoints.Count; i++)
            {
                if (i != midPoints.Count - 1)
                {
                    GenerateBoxGrid(midPoints[i], midPoints[i + 1], ref boxGrid);
                }
            }

            GenerateBoxGrid(midPoints[midPoints.Count - 1], currentObject.endPoint, ref boxGrid);
        }
        else
        {
            GenerateBoxGrid(currentObject.startPoint, currentObject.endPoint, ref boxGrid);
        }
    }
示例#5
0
    //returns the vector in witch the endpoint is facing.
    private Vector3 TunnelsDirection(TunnelPieces tunnelObject)
    {
        Vector3 directionVector = tunnelObject.endPoint.position - tunnelObject.midPoint.position;

        return(directionVector.normalized);
    }