Version: 5.4 (switch to 5.5b)
言語English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Mathf.MoveTowards

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

マニュアルに切り替える
public static function MoveTowards(current: float, target: float, maxDelta: float): float;
public static float MoveTowards(float current, float target, float maxDelta);

Parameters

current 現在の値
target 移動先となる値
maxDelta 値に適用される最大の変更

Description

current から target まで、maxDelta のスピードで移動します。

これは基本的に Mathf.Lerp と同じですが、代わりに関数は速度が maxDelta を超えないようにします。 MaxDelta の値が負の場合は target から遠ざかります。

var currStrength: float;
var maxStrength: float;
var recoveryRate: float;

function Update() { currStrength = Mathf.MoveTowards(currStrength, maxStrength, recoveryRate * Time.deltaTime); }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public float currStrength; public float maxStrength; public float recoveryRate; void Update() { currStrength = Mathf.MoveTowards(currStrength, maxStrength, recoveryRate * Time.deltaTime); } }