ZEPETO 캐릭터의 현재 위치 가져오기
3 분
이 가이드는 ZEPETO 월드 내에서 로컬 플레이어의 ZEPETO 캐릭터의 현재 위치를 확인하는 방법을 보여줍니다.
위치 정보는 변환 객체의 위치에 저장되므로, ZEPETO 플레이어의 변환에 접근하여 그들의 위치를 찾는 것이 중요합니다.
1단계 : 스크립트 작성하기
- [Project] 패널의 왼쪽 상단 모서리에 있는 [+] 메뉴를 선택하거나 자산 > 생성 > ZEPETO > TypeScript를 선택합니다.
- 추가된 스크립트의 이름을 GetPosition으로 바꾸고 다음과 같이 샘플 스크립트를 작성합니다.
import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
import { ZepetoPlayers, ZepetoCharacter } from 'ZEPETO.Character.Controller';
import { Text } from 'UnityEngine.UI';
import { WorldService } from 'ZEPETO.World';
export default class GetPosition extends ZepetoScriptBehaviour {
public debugText: Text;
private _zepetoCharacter: ZepetoCharacter;
Start() {
ZepetoPlayers.instance.OnAddedLocalPlayer.AddListener(() => {
// Get the ZepetoCharacter of the local player using their userId.
this._zepetoCharacter = ZepetoPlayers.instance.GetPlayer(WorldService.userId).character;
})
}
Update() {
// Update the debug text with the current player's position.
this.debugText.text = "현재 플레이어 위치 : " + this._zepetoCharacter.transform.position.ToString();
}
}❗️ 주의 멀티플레이어 환경에서 GetPlayer() 함수를 사용하려면 sessionId를 매개변수로 사용해야 합니다.
📘 다음 가이드를 참조하십시오. [ZEPETO Players]
- 장면에 GameObject를 추가하고 이름을 CharacterPosition으로 변경합니다.
- 작성한 GetPosition ZEPETOScript를 추가하고, Hierarchy 창에서 드래그 앤 드롭하여 ZEPETO Script Inspector 창의 속성에 버튼 UI를 연결합니다.

2단계 : 실행
- 재생 버튼을 누르면 텍스트 UI를 통해 캐릭터의 실시간 위치를 확인할 수 있습니다.
