How Do I modify speed to be slower?
using UnityEngine; using System.Collections;
public class MaterialChange : MonoBehaviour {
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);
}
}
Answer by cjdev · Jun 15, 2016 at 04:16 AM
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.
Thanks cjdev!
I ended up dividing time to a fraction (or more)
Color color = Color.Lerp(red, blue, $$anonymous$$athf.PingPong ((Time.time/ 10) * speed, 1));
Answer by Develax · Jun 10, 2019 at 07:12 PM
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;
}
Your answer
Follow this Question
Related Questions
Object Coordinates with timecode 0 Answers
How to make my powerup last for about five seconds then go back to normal? 3 Answers
How to Get Speed to Very Gradually Pick Up Over Time? 2 Answers
How to change FirstPerson Controller Speed OnTriggerEnter event for a certain amount of time? 0 Answers
Time delay enemy respawn 3 Answers