-
-
Save todorok1/5df5592633685bf5e3340663eded05ec to your computer and use it in GitHub Desktop.
Lerpメソッドのサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 移動前と移動後の位置を指定します。 | |
public Vector3 startPos; | |
public Vector3 endPos; | |
// オブジェクトの移動にかかる時間を設定します。 | |
public float moveTime = 3.0f; | |
// 処理の経過時間を保持します。 | |
float elapsedTime; | |
void Update() | |
{ | |
if (elapsedTime > moveTime) | |
{ | |
return; | |
} | |
// 経過時間のフィールドに前のフレームからの経過時間を加算します。 | |
elapsedTime += Time.deltaTime; | |
// 移動時間に対する経過時間の割合を計算します。 | |
float rate = Mathf.Clamp01(elapsedTime / moveTime); | |
// 移動時間に対する経過時間の割合を使って位置の線形補間を行います。 | |
Vector3 currentPos = Vector3.Lerp(startPos, endPos, rate); | |
gameObject.transform.position = currentPos; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment