/**
  *  FOR CHAPTER 4: Find the destination of the portal given discontunuity.
  */
 public Spline FindDestinationSpline(float discontinuityX)
 {
     foreach (Transform currSplineTransform in GameObject.Find("Splines").transform)
     {
         GameObject currSpline   = currSplineTransform.gameObject;
         Spline     spline       = currSpline.GetComponent <Spline>();
         float      splineStartX = spline.GetControlPointPosition(0).x + spline.transform.position.x;
         splineStartX = (Mathf.Round(splineStartX * 10f)) / 10;
         if (Mathf.Approximately(splineStartX, discontinuityX))
         {
             return(spline);
         }
     }
     return(null); // destination not found!
 }
Пример #2
0
        /// <summary>
        /// Create new renderer at the end of the current one
        /// </summary>
        public GameObject ConnectNewRenderer()
        {
            Vector3    lastPointPosition = _spline.GetControlPointPosition(_spline.ControlPointCount - 1);
            Quaternion lastPointRotation = _spline.GetRotation(1);

            Vector3    position = transform.TransformPoint(lastPointPosition);
            GameObject clone    = Instantiate(this.gameObject, position, _spline.GetRotation(1) * Quaternion.LookRotation(_spline.GetDirection(1)));

            Spline newRendererSpline = clone.GetComponent <Spline>();

            newRendererSpline.Reset();
            newRendererSpline.ResetRotations(lastPointRotation);

            SplineMeshRenderer newRendererSplineMeshRenderer = clone.GetComponent <SplineMeshRenderer>();

            newRendererSplineMeshRenderer.realtimeMeshGeneration = realtimeMeshGeneration;
            newRendererSplineMeshRenderer.ExtrudeMesh();

            return(clone);
        }