IEnumerator Shaking(float duration, float magnitude) { float elapsed = 0.0f; while (elapsed < duration) { float t = Ease.EaseOut(elapsed / duration); float mag = Mathf.Lerp(magnitude, 0, t); float x = Random.Range(-1f, 1f) * mag; float y = Random.Range(-1f, 1f) * mag; cam.transform.localPosition = basePos + new Vector3(x, y, 0); elapsed += Time.deltaTime; yield return(null); } cam.transform.localPosition = basePos; }
private void Update() { if (!move) { return; } if (goingForward) { progress += Time.deltaTime / duration; if (progress > 1f) { if (mode == SplineWalkerMode.Once) { progress = 1f; } else if (mode == SplineWalkerMode.Loop) { progress -= 1f; } else { progress = 2f - progress; goingForward = false; } } } else { progress -= Time.deltaTime / duration; if (progress < 0f) { progress = -progress; goingForward = true; } } float easedProgress = progress; switch (easing) { case EaseType.SmoothStep: easedProgress = Ease.SmoothStep(progress); break; case EaseType.SmootherStep: easedProgress = Ease.SmootherStep(progress); break; case EaseType.EaseIn: easedProgress = Ease.EaseIn(progress); break; case EaseType.EaseOut: easedProgress = Ease.EaseOut(progress); break; case EaseType.ExpOut: easedProgress = Ease.ExpOut(progress); break; } Vector3 position = spline.GetPoint(progress); transform.position = position; if (lookForward) { transform.LookAt(position + spline.GetDirection(progress)); } }