//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)); }
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); } }
//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); }
//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); } }
//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); }