void Update() { if (mState == "Reset" || mState == "Stopped" || mNodes.Count < 4) { return; } mCurrentTime += Time.deltaTime; // We advance to next point in the path if (mCurrentTime >= ((SplineNode)mNodes[mCurrentIdx + 1]).Time) { if (mCurrentIdx < mNodes.Count - 3) { mCurrentIdx++; if (mSplineController.RotateEnable) { targetRotation = mSplineController.LookRotation(mCurrentIdx - 1, mCurrentIdx); } } else { if (mState != "Loop") { mState = "Stopped"; // We stop right in the end point transform.position = ((SplineNode)mNodes[mNodes.Count - 2]).Point; // We call back to inform that we are ended if (mOnEndCallback != null) { mOnEndCallback(); } } else { mCurrentIdx = 1; mCurrentTime = 0; if (mSplineController.RotateEnable) { transform.rotation = mSplineController.LookRotation(0, 1); targetRotation = this.transform.rotation; } } } } if (mState != "Stopped") { // Calculates the t param between 0 and 1 float param = (mCurrentTime - ((SplineNode)mNodes[mCurrentIdx]).Time) / (((SplineNode)mNodes[mCurrentIdx + 1]).Time - ((SplineNode)mNodes[mCurrentIdx]).Time); // Smooth the param param = MathUtils.Ease(param, ((SplineNode)mNodes[mCurrentIdx]).EaseIO.x, ((SplineNode)mNodes[mCurrentIdx]).EaseIO.y); transform.position = GetHermiteInternal(mCurrentIdx, param); //Rotate if (mSplineController.RotateEnable) { this.transform.rotation = Quaternion.Lerp(this.transform.rotation, targetRotation, mSplineController.RotateSpeed); } } }