예제 #1
0
    private void ShowDirections()
    {
        Handles.color = Color.green;
        Vector3 point = spline.GetPoint(0f);

        Handles.DrawLine(point, point + spline.GetDirection(0f) * directionScale);
        int steps = stepsPerCurve * spline.CurveCount;

        for (int i = 1; i <= steps; i++)
        {
            point = spline.GetPoint(i / (float)steps);
            Handles.DrawLine(point, point + spline.GetDirection(i / (float)steps) * directionScale);
        }
    }
예제 #2
0
        private void Update()
        {
            if (goingForward)
            {
                Progress += Time.deltaTime / Duration;
                if (Progress > 1.0f)
                {
                    switch (Mode)
                    {
                    case SplineWalkerModes.Once:
                        Progress = 1.0f;
                        break;

                    case SplineWalkerModes.Loop:
                        Progress -= 1.0f;
                        break;

                    case SplineWalkerModes.PingPong:
                        Progress     = 2.0f - Progress;
                        goingForward = false;
                        break;
                    }
                }
            }
            else
            {
                Progress -= Time.deltaTime / Duration;
                if (Progress < 0f)
                {
                    Progress     = -Progress;
                    goingForward = true;
                }
            }

            Vector3 position = Spline.GetPoint(Progress);

            transform.localPosition = position;
            if (LookForward)
            {
                transform.LookAt(position + Spline.GetDirection(Progress));
            }
        }