728x90
반응형
1. Random.Range
Random.Range는 주어진 범위 내에서 랜덤 한 값을 반환한다.
이 함수는 파라미터에 int와 float 같이 자료형에 대해 다르게 동작한다.
// min 이상 max 미만의 값을 반환한다.
int randomInt = Random.Range(0, 10); // 0 ~ 9
// min 이상 max 이하의 값을 반환한다.
float randomFloat = Random.Range(0f, 10f); // 0.0 ~ 10.0
2. Random.value
Random.value는 0.0 이상 1.0 이하의 랜덤 한 값을 반환한다.
float randomValue = Random.value; // 0.0 ~ 1.0
3. Random.insideUnitCircle
Random.insideUnitCircle은 반지름이 1인 원 내부의 임의의 점을 반환한다.
Vector2 randomInsideCircle = Random.insideUnitCircle;
4. Random.insideUnitSphere
Random.insideUnitSphere는 반지름이 1인 구 내부의 임의의 점을 반환한다.
Vector3 randomInsideSphere = Random.insideUnitSphere;
5. Random.onUnitSphere
Random.onUnitSphere는 구의 표면 상의 임의의 점을 반환한다.
Vector3 randomOnSphere = Random.onUnitSphere;
6. Random.rotation
Random.rotation은 임의의 회전을 나타내는 쿼터니언 값을 반환한다.
Quaternion randomRotation = Random.rotation;
7. Random.ColorHSV
Random.ColorHSV는 임의의 색상을 반환한다.
HSV 색상 모델을 사용하여 특정 범위의 색상을 생성할 수도 있다.
// 기본 범위: 모든 색상
Color randomColor = Random.ColorHSV();
// 특정 범위의 색상
Color specificRandomColor = Random.ColorHSV(0f, 1f, 0.5f, 1f, 0.5f, 1f); // 색상, 채도, 명도 범위 지정
728x90
반응형
'Unity' 카테고리의 다른 글
Dictionary, Hashtable, HashSet의 비교와 사용법 (3) | 2024.07.14 |
---|---|
Serializable과 SerializeField의 역할과 활용 (0) | 2024.07.09 |
SMB(State Machine Behaviors)와 FSM(Finite State Machine) 비교 (0) | 2024.07.03 |
Animator StringToHash 유니티 최적화 (0) | 2024.07.02 |
ScriptableObject 사용 방법 (0) | 2024.06.26 |