basically the "2f" is the "speed" in such statements in a frame-based system like Unity.
here in PingPong, the "2" is the time of the ping and the pong
As Gunnar explains if you are concerned with the *meters per second of the object, you have to do this
float desiredMPS = 10f; // you want the object to move at 10 mps
float knownDistance = max - min;
float howManySecondsForLoop = knownDistance / desiredMPS;
You would use "howManySecondsForLoop" as the "2" for the PingPong.
in general, to change that at certain times or places,
public float pongTime = 2.5f // .. or whatever as above
Vector3 p = transform.position;
float newX = Mathf.PingPong(Time.time*pongTime,max-min)+min;
p.x = newX;
transform.position = p;
and experiment with changing the "pongTime" yourself. (Just do it in the editor.)
In code it is likely you will use "Invoke" or similar to change it.
Invoke( "InThreeSecondsSlowItDown", 3f);
private void InThreeSecondsSlowItDown()
{
pongTime = .75f; // or calculate as above
}
Or you might do something like this
if ( .. distance .. < .. width of enemy *2 .. )
pongTime = pongTime * .1f; // or calculate as above
Enjoy
in short try this
float desiredMPS;
// you want the object to move at that many meters per second
// at first try say "3" in the Editor
void Update()
{
float knownDistance = max - min;
float howManySecondsForLoop = knownDistance / desiredMPS;
public float pongTime = howManySecondsForLoop;
Vector3 p = transform.position;
float newX = Mathf.PingPong(Time.time*pongTime,max-min)+min;
p.x = newX;
}