-
-
Save todorok1/a1a1aef97745760e80bdc6cd48e82322 to your computer and use it in GitHub Desktop.
UnityのMathfでClampを使ったサンプル
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
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
/// <Summary> | |
/// MathfのClampの動作を確認するためのクラスです。 | |
/// </Summary> | |
public class ClampChecker : MonoBehaviour | |
{ | |
// Clampとして値を制限する範囲を指定します。 | |
readonly float clampMin = 0f; | |
readonly float clampMax = 10f; | |
void Start() | |
{ | |
// 範囲内の値を入力します。 | |
float checkValue = 5f; | |
ClampTest(checkValue); | |
// 下限より小さい値を入力します。 | |
checkValue = -5f; | |
ClampTest(checkValue); | |
// 上限より大きい値を入力します。 | |
checkValue = 20f; | |
ClampTest(checkValue); | |
} | |
/// <Summary> | |
/// 引数で指定された値がClampメソッドを通してどの値になるかを確認します。 | |
/// </Summary> | |
void ClampTest(float value) | |
{ | |
float clamped = Mathf.Clamp(value, clampMin, clampMax); | |
Debug.Log($"{value} を入力した結果、Clampを通した値は {clamped} でした。"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment