0. 서문
게임 제작 간 무기 위치 초기화 동작에 오류 발생
1. 문제 원인
객체의 위치 초기화를 'gameObject.position = Vector3.zero' 방식으로 초기화를 적용함.
mWeaponPool.transform.position = Vector3.zero;
이때, position 값은 'World Space' 기준으로 적용됨
- position: World Space 내 transform 좌표 (게임 내 공간에 따라 x,y,z가 결정)
- localPosition: 부모 객체 transform 기준 상대 좌표
+) Screen Space
2. 해결 방안
부모 객체와의 상대 좌표를 활용한 초기화 적용
3. 적용 방법
// mWeaponPool.transform.position = Vector3.zero; (기존 초기화 방법, 오류 발생)
mWeaponPool.transform.localPosition = Vector3.zero;
mWeaponPool.transform.localRotation = Quaternion.identity;
4. 참고 자료
https://docs.unity3d.com/ScriptReference/Transform-localPosition.html
Unity - Scripting API: Transform.localPosition
Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close
docs.unity3d.com
https://docs.unity3d.com/ScriptReference/Transform-position.html
Unity - Scripting API: Transform.position
Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close
docs.unity3d.com
'--------게임만들기-------- > |unity| by C#' 카테고리의 다른 글
[Unity] Day6 - 도끼, 마늘 무기 구현 (0) | 2024.06.07 |
---|---|
[Unity] Day5 - 단검 무기 구현, 버그 개선 (position, localPosition) (0) | 2024.06.06 |
[Unity] Day4 - 싱글턴 구현 완료, 투사체 방사 로직 구현 (0) | 2024.06.05 |
[Unity] 방사형 공격 (Rotate, rotation, Quaternion) (0) | 2024.06.05 |
[unity] Day3 - 싱글턴 구현(static function) (0) | 2024.06.04 |