void OnGUI() { // before using the spline, ensure it's initialized and the Controller is available if (mSpline == null || !mSpline.IsInitialized || !Controller) { return; } var e = Event.current; switch (e.type) { case EventType.MouseDrag: // Start a new line? if (mResetSpline) { mSpline.Clear(); // delete all Control Points Controller.gameObject.SetActive(true); Controller.Prepare(); // set the Controller to start mLastControlPointPos = e.mousePosition; // Store current mouse position addCP(e.mousePosition); // add the first Control Point mResetSpline = false; } else { // only create a new Control Point if the minimum distance is reached float dist = (e.mousePosition - mLastControlPointPos).magnitude; if (dist >= StepDistance) { mLastControlPointPos = e.mousePosition; addCP(e.mousePosition); if (!Controller.IsPlaying) { Controller.Play(); } } } break; case EventType.MouseUp: mResetSpline = true; break; } }