123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PitchOscillator : MonoBehaviour
- {
-
-
-
- [Tooltip("The path it takes to oscillate. Makes it simple to set a pattern in the Inspector. ")]
- public AnimationCurve animationCurve;
-
-
-
- [Tooltip("How long a full oscillation lasts (from start to finish of animationCurve). ")]
- public float secondsPerOscillation = .95f;
-
-
-
- [Tooltip("Scales the values in animationCurve, since it's difficult to specify values outside -1 and 1 in the Inspector. ")]
- public float distanceScale = 2;
-
-
-
-
- private float timer = 0f;
-
-
-
- private Vector3 startposition;
-
- void Start ()
- {
- startposition = transform.localPosition;
- }
-
-
- void Update ()
- {
-
- timer += Time.deltaTime;
- if(timer >= secondsPerOscillation)
- {
- timer = timer % secondsPerOscillation;
- }
-
- float newxpos = animationCurve.Evaluate(timer / secondsPerOscillation) * distanceScale;
- transform.localPosition = startposition + transform.localRotation * Vector3.right * newxpos;
- }
- }
|