유니티 C# 반올림, 올림, 내림, 소수점 2자리 버리기 간단 구현
- 반올림 Round
float myFloat = 3.6f;
int myInt = Mathf.RoundToInt(myFloat);
Debug.Log(myInt); // 출력: 4
- 반올림 Ceil
float myFloat = 3.2f;
int myInt = Mathf.CeilToInt(myFloat);
Debug.Log(myInt); // 출력: 4
- 내림 Floor
float myFloat = 3.8f;
int myInt = Mathf.FloorToInt(myFloat);
Debug.Log(myInt); // 출력: 3
- 소수점 전부 버리기
float myFloat = 3.14159f;
int myInt = Mathf.FloorToInt(myFloat);
Debug.Log(myInt); // 출력: 3
- 소수점 1자리 버리기
float myFloat = 123.45678f;
float truncatedFloat = Mathf.Floor(myFloat * 10f) / 10f;
Debug.Log(truncatedFloat); // 출력: 123.4
- 소수점 2자리 버리기
float myFloat = 123.45678f;
float truncatedFloat2 = Mathf.Floor(myFloat * 100f) / 100f;
Debug.Log(truncatedFloat2); // 출력: 123.45
또는
myFloat = float.Parse(myFloat.ToString("N1"));
참고할만한 글
유니티 C# 두 점 사이의 각도 구하기 간단 구현 Unity Vector2 Angle
코드 작성 using UnityEngine; public class AngleCalculator : MonoBehaviour { public Transform pointA; public Transform pointB; void Start() { Vector2 direction = pointB.position - pointA.position; float angle = Vector2.Angle(Vector2.right, direction); D
parksh3641.tistory.com
유니티 C# Enum Count 길이 간단 구하기
코드 작성 using System.Collections; using System.Collections.Generic; using UnityEngine; public enum MoneyType { Gold = 0, Crystal } public class ExampleEnum : MonoBehaviour { public MoneyType moneyType = MoneyType.Gold; void GetEnumCount() { int count
parksh3641.tistory.com
블로그 운영자가 만든 모바일 게임 다운 해보기
윈드체스 : 픽셀아트 보드게임 블루북 게임즈 모바일 게임 추천
윈드체스 : 운명의 타이밍진정한 "픽셀아트" 보드 게임 진정한 "실력" 게임 진정한 "PVP" 그리고.. "재미있는 스토리" =============================================== 공식 카페 https://cafe.naver.com/windchess =========
parksh3641.tistory.com