저는 Mathf.Sign를 Sine함수와 헷갈리는 바람에... 약간 머리가 아팠네요 하하
![](https://t1.daumcdn.net/keditor/emoticon/friends1/large/021.gif)
Sign은 Sine함수가 아닌 Sign(부호)를 나타냅니다.
/// <summary>
/// <para>Returns the sign of f.</para>
/// </summary>
/// <param name="f"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Sign(float f) => (double) f >= 0.0 ? 1f : -1f;
public static float Sign(float f) => (double) f >= 0.0 ? 1f : -1f;
Sign 함수는 값을 받아와서 값이 양수면 1을, 음수면 -1을 돌려줍니다.
private float SnapInput(float input, float threshold = 0.5f)
{
if (Mathf.Abs(input) > threshold)
{
return Mathf.Sign(input);
}
return 0f;
}
위 코드는 예시코드입니다.
input값을 받아서 threshold(0.5)보다 크면 return Mathf.Sign(input)을 해주는데요, 이때 input이 0.6이라면 1을 반환해주게 됩니다. 반대로 input이 -0.6이라면 절대값을 취했기 때문에 threshold보단 크는데, 이때는 -1을 반환하게 됩니다.