CREATE YOUR WORLD
Scripting

Script Import

3min
게임 오브젝트에 연결된 것 외에도, zepetoscript는 다른 스크립트에서 직접 사용할 수 있습니다 zepetoscript를 라이브러리나 모듈처럼 간단히 가져와서 사용할 수 있습니다 typescript 문법에서는 zepetoscript 파일에 대한 상대 경로를 사용해야 합니다 아래 상황을 고려할 때, extracomponent를 scriptimport에 가져오려면 다음 문법을 사용해야 합니다 다음 예시는 lib 폴더에 위치한 extracomponent ts를 호출하기 위한 scriptimport ts의 선언입니다 typescript import extracomponent from ' /lib/extracomponent'; 👍 팁 다른 ts 파일을 가져올 때 경로를 정확히 지정하는 것이 중요합니다 상대 경로 표기법에 익숙해지세요 / 는 현재 디렉토리를 나타냅니다 / 는 부모 디렉토리를 나타내며, 즉 현재 디렉토리의 한 단계 위에 있는 디렉토리입니다 가져온 스크립트에서 선언된 내보낸 함수와 변수를 샘플처럼 직접 참조하여 접근할 수 있습니다 this gameobject addcomponent\<extracomponent>(); const extracomponent = this gameobject getcomponent\<extracomponent>(); // 메서드 호출로 값 가져오기 const count = extracomponent getcount(); // 메서드 호출로 값 설정하기 extracomponent setcount(0); // 공용 속성 가져오기 const resultstring = extracomponent stringproperty; 다음은 가져온 typescript를 보여주는 샘플 코드입니다 import { zepetoscriptbehaviour } from 'zepeto script'; import { text } from 'unityengine ui'; // 경로에서 사용자 정의 스크립트 가져오기 import extracomponent from ' /lib/extracomponent'; export default class scriptimport extends zepetoscriptbehaviour { public resultui text; private extcomponent extracomponent; start() { // 스크립트 컴포넌트 추가 this gameobject addcomponent\<extracomponent>(); this extcomponent = this gameobject getcomponent\<extracomponent>(); } update() { // 메서드 호출로 값 가져오기 const count = this extcomponent getcount(); if (count > 10) { // 메서드 호출로 값 설정하기 this extcomponent setcount(0); } // 공개 속성 가져오기 const resultstring = this extcomponent stringproperty; // 결과 출력 console log(`result ${resultstring}`); this resultui text = resultstring; } } extracomponents에 대한 샘플 코드입니다 import { zepetoscriptbehaviour } from 'zepeto script'; export default class extracomponent extends zepetoscriptbehaviour { public stringproperty string; private message string; private count int; start() { this message = "안녕 제페토!"; this count = 0; } update() { this stringproperty = `${this message} ${this count++}`; } getcount() { return this count; } setcount(newcount int) { this count = newcount; } } 아래의 테스트 코드 출력 화면을 확인하세요