public Color red;
public Color blue;
public float speed;
public Material colorMaterial;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Color color = Color.Lerp(red, blue, Mathf.PingPong(Time.time * speed, 1));
colorMaterial.SetColor("_Color", color);
}
Since speed is the float variable you’ve exposed in the inspector you can decrease it there or you can reassign it to a new value in the Start method. Alternatively, you can just multiply by a fraction inside the Mathf.PingPong(Time.time * speed, 1) such that you’re effectively multiplying speed by a fraction.
Here is a version of the PingPong function with a parameter pingPontPeriod to which you can pass a time value for the full motion amplitude. If you skip the second parameter the motion will complete within 1 second (by default) no matter how large the length is.
private float NormalPingPong(float length, float pingPontPeriod = 1f)
{
float time = Time.time;
float mod = time % pingPontPeriod;
float result = (mod < pingPontPeriod / 2f) ? mod : pingPontPeriod - mod;
return result / pingPontPeriod * length * 2;
}