I have made my own version of the Vector2.ClampMagnitude() method. The problem with that method is that it only clamps to a maximum value and I wanted to set both a low and a high value, plus I also wanted to have different blocks either slow or speed up the ball.
I solved this with two methods. The first one you call will either the low or high value you want it to be clamped to. You only call this if it outside the designated range. The second one will change the velocity by a multiple of the current speed, so 0.9f will slow it by 10% and 1.1f will speed it up by 10%, etc.
I have included some Debug.Log() statements that are commented out, in case you want to check what it does in ClampVelocity().
/***
* ClampVelocity() will set the velocity to the passed value.
***/
private void ClampVelocity(float velocityLimit)
{
//Debug.Log("Before magnitude = " + myRigidBody2D.velocity.magnitude +
// ", x = " + myRigidBody2D.velocity.x + ", y = " + myRigidBody2D.velocity.y);
ChangeVelocity(velocityLimit / myRigidBody2D.velocity.magnitude);
//Debug.Log("After magnitude = " + myRigidBody2D.velocity.magnitude +
// ", x = " + myRigidBody2D.velocity.x + ", y = " + myRigidBody2D.velocity.y);
} // ClampVelocity()
/***
* ChangeVelocity() will make the ball velocity change by the multiple of the
* new value given. The change is not exact and will tend to be a bit over or under
* the amount asked for, due to rounding, but it will be fairly close.
* Examples:
* ChangeVelocity(0.9f) will slow the ball down by about 1/10th
* ChangeVelocity(1.1f) will speed the ball up by about 1/10th
***/
public void ChangeVelocity(float magnitudeChange)
{
myRigidBody2D.velocity *= magnitudeChange;
} // ChangeVelocity()
Enjoy!