Пример #1
0
    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent <Rigidbody>();

        if (!spline.isLooping)
        {
            segment = 1;
        }

        rb.MovePosition(spline.GetCurvePos(t, segment) + new Vector3(0, offsetY, 0));
        transform.forward = spline.GetCurveForward(t, segment);
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        transform.position = spline.GetCurvePos(t, segment);
        t -= speed * Time.deltaTime;
        if (t >= 1.0f)
        {
            ++segment;
            if (spline.isLooping && segment == spline.controlPointsList.Length)
            {
                segment = 0;
            }
            else if (!spline.isLooping && segment == spline.controlPointsList.Length - 2)
            {
                segment = 1;
            }
            t = 0.0f;
        }

        if (t < 0.0f)
        {
            --segment;
            if (spline.isLooping && segment < 0)
            {
                segment = spline.controlPointsList.Length - 1;
            }
            else if (!spline.isLooping && segment < 1)
            {
                segment = spline.controlPointsList.Length - 3;
            }
            t = 1.0f;
        }
    }