Exemple #1
0
    private void AddNewPoint()
    {
        // First point at zero
        Vector2 pos = Vector2.zero;

        if (spline.Count == 1)
        {
            // Second point up & right 2 units
            pos = spline.GetPoint(0) + Vector2.up * 2.0f + Vector2.right * 2.0f;
        }
        else if (spline.Count > 1)
        {
            // Third+ point extended from  previous & varied a little
            // rotate left/right alternately for interest
            Vector2 endpos = spline.GetPoint(spline.Count - 1);
            Vector2 diff   = endpos - spline.GetPoint(spline.Count - 2);
            float   angle  = spline.Count % 2 > 0 ? 30.0f : -30.0f;
            diff = Quaternion.AngleAxis(angle, Vector3.forward) * diff;
            pos  = endpos + diff;
        }
        spline.AddPoint(pos);
    }