Unity의 UI에서 가끔은 필요에 따라 크기나 위치를 여러 가지로 변경해야 할 때가 있다.
자주 사용하지 않지만 어쩌다 사용하려고 보면 까먹어서 다시 검색하게 되는데 이를 정리해 본다.
1. Rect Transform
- 값 읽기
> offsetMin; // Left, Bottom
> offsetMax; // Right, Top
- 값 적용
> GetComponent< RectTransform >().offsetMin = new Vector2(100, 100); // (left, bottom) 적용됨
> GetComponent< RectTransform >().offsetMax = new Vector2(100, 100); // (-right, -top) 적용됨
2. Anchors
- 값 읽기
> anchorMin ; // 2D vector
> anchorMax; // 2D vector
- 값 적용
> GetComponent().anchorMin = new Vector2(0, 0); // 0 ~ 1 float
> GetComponent().anchorMax = new Vector2(1, 1);
3. Pivot
- Anchors와 같은 방식(2D Vector) : GetComponent().pivot;
4. Rotation
- 값 읽기
> rotation; // localRotation // 3D vector
- 값 적용
> GetComponent<RectTransform>().rotation = Quaternion.Euler(0, 0, 0);
5. Scale
- 값 읽기
> localScale; // 3D vector
- 값 적용
> GetComponent<RectTransform>().localScale = new Vector3(1, 1, 1);
6. Image(Script) Color 변경
- 값 읽기
> color; // vector4
- 값 적용
> GetComponent<Image>().color = new Color(1, 0.5f, 1, 0.5f);
요정도만 정리해도 다양하게 활용할 수 있겠다.
'개발 관련 > SW, App 관련' 카테고리의 다른 글
주말의 잉여 작업 - 게임 속의 확률 (6) | 2024.07.23 |
---|---|
Anaconda Jupyter Notebook 실행 오류 (2) | 2024.05.07 |
darknet / darkflow 설치, 아나콘다로 실행 과정에서의 오류들 정리 (0) | 2024.04.16 |
Unity EventTrigger 사용 (0) | 2024.02.04 |
아나콘다 이전버전 설치 (1) | 2024.01.05 |
댓글