Mathf.Clam(value, min, max) 는 value라는 계산식을 min부터 max사이값만 허용시켜주는 함수이다. value가 min보다 작을 경우 min 값, max보다 넘어갈 경우 max값으로 반환한다는 상한선을 정해주는 함수이다.
해당 함수를 통해 슬로우를 최대 80퍼센트 적용하여 공격력에 비례하여 슬로우를 적용시킬 수 있다.
public void OnDeBuffed(CharacterStat stat)
{
if (_isDead || _isSlowed)
return;
float slowPercent = Mathf.Clamp(stat.Attack * 0.8f, 0f, 80f);
float slowSpeed = Mathf.Max(0.2f, _moveSpeed * (1 - slowPercent / 100f));
MoveSpeed = slowSpeed;
_isSlowed = true;
Debug.Log($"슬로우 적용: {slowPercent}% | 현재 이동 속도: {_moveSpeed}");
GameManager.Instance.Coroutine.RunCoroutine(RemoveSlowEffectCo(1.5f));
}
예시
- Attack = 50 -> 50 * 0.8 = 40 , _moveSpeed * 0.6
- Attack = 200 -> 200 * 0.8 = 160 (Mathf.Clamp() 함수에 의해 80f 로 조정), _moveSpeed * 0.2
'Unity' 카테고리의 다른 글
[Unity] typeof(T) 와 GetType()의 차이 (0) | 2025.02.18 |
---|---|
[Unity] CSV 파일 적용하기 (1) | 2024.12.11 |
[Unity] Sprite Atlas 및 스프라이트 동적 변화 (0) | 2024.11.25 |
[Unity] EventSystem.current.IsPointerOverGameObject() (0) | 2024.11.20 |
[Unity] Pooling에서 Queue와 Stack 의 선택 (지시어 사용) (0) | 2024.11.19 |