public static float MoveTowards (float current, float target, float maxDelta);

Parameters

current当前值。
target要向其靠近的值。
maxDelta对值应用的最大变化。

Description

将值 currenttarget 靠近。

This is essentially the same as Mathf.Lerp but instead the function will ensure that the speed never exceeds maxDelta. Negative values of maxDelta pushes the value away from target.

using UnityEngine;

public class Example : MonoBehaviour { float currStrength; float maxStrength; float recoveryRate;

void Update() { currStrength = Mathf.MoveTowards(currStrength, maxStrength, recoveryRate * Time.deltaTime); } }