Scale Oscillator

After following the code for the movement oscillator I tried to do the same with scale. It was very simple to do this.

public class Oscillator : MonoBehaviour

{
    [SerializeField] Vector3 scaleVector;
    [Range(0, 1)] [SerializeField] float scaleFactor; // 0 for not moved, 1 for fully moved.

    Vector3 startingScale; // must be stored for absolute movement

    // Start is called before the first frame update
    void Start()
    {
        startingScale = transform.localScale; 
    }

    // Update is called once per frame
    void Update()
    {
        Vector3 scaleOffset = scaleVector * scaleFactor;
        transform.localScale = startingScale + scaleOffset;
    }
}
1 Like

Nice job! Thanks for sharing this!

Privacy & Terms