Skip to content

Instantly share code, notes, and snippets.

@Sacristan
Created October 26, 2016 07:47
Show Gist options
  • Save Sacristan/f73a988f9fbacc6426170aa0300a3e32 to your computer and use it in GitHub Desktop.
Save Sacristan/f73a988f9fbacc6426170aa0300a3e32 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;

public class ScalePulse : MonoBehaviour
{
    [System.Serializable]
    private struct Scale
    {
        [SerializeField]
        [Range(0f, 3f)]
        public float min;
        [SerializeField]
        [Range(0f, 3f)]
        public float max;

        public Scale(float pMin, float pMax)
        {
            min = pMin;
            max = pMax;
        }
    }

    [SerializeField]
    [Range(0f, 2f)]
    private float timeScale = 1f;

    [SerializeField]
    private Scale scale = new Scale(1f, 2f);

    void Update()
    {
        float progress = Mathf.PingPong(Time.time * timeScale, 1f);
        float multiplier = Mathf.Lerp(scale.min, scale.max, progress);

        transform.localScale = Vector3.one * multiplier;
    }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment