커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
4주차 강의 관련
undefined주차
북마크
윤*혜
댓글
1
추천
0
조회수
15
조회수
15
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.



강의 4-5 점프 기능을 추가하는 부분에서 스크립트에 BtnJump를 붙여 넣으니 하단과 같이 오류가 나와 실행이 되지 않습니다.

어떻게 처리해야 할지 안내 부탁드립니다.


스파르타 즉문즉답




작성한 코드 및 에러 메세지

import { Coroutine, GameObject, Vector3, WaitForSeconds } from 'UnityEngine';

import { ZepetoScriptBehaviour } from 'ZEPETO.Script';

import ClientScript from './ClientScript';


export default class BtnJump extends ZepetoScriptBehaviour {


    // BtnJump 클래스가 담겨있는 인스턴스 */

    private static instance: BtnJump;

    /** BtnJump의 함수나 변수에 접근할 수 있도록 인스턴스를 반환해줄 함수 */

    static GetInstance(): BtnJump {

        if (!BtnJump.instance) {

            const targetObj = GameObject.Find("btnJump");

            if (targetObj) BtnJump.instance = targetObj.GetComponent<BtnJump>();

        }

        return BtnJump.instance;

    }


    /** 점프 상태를 true/false로 표현하는 멤버 변수 */

    public isJumping: boolean = false;


    // ========== 추가

    /** 충전한 점프력을 담을 멤버 변수 */

    public jumpPower: number = 0;


    /** 코루틴 고유 리턴값 담을 멤버 변수 */

    private coChargeJumpPower: Coroutine = null;

    // ========== 추가


    // ========== 추가

    // 실제 점프력을 충전할 함수

    *ChargeJumpPower() {

        // 캐릭터가 점프 상태가 아닐 때만

        if (this.isJumping === false) {

            // 점프 상태로 전환하고

            this.isJumping = true;

            while (true) {

                // 0.1초 마다

                yield new WaitForSeconds(0.03);

                // 점프력 충전

                this.jumpPower += 0.25;

            }

        }

    };

    // ========== 추가


    // 버튼을 누르고 있을 때 호출될 함수 선언

    btnJumpDown() {

        // ========== 추가

        // 코루틴으로 함수를 실행시키고 coChargeJumpPower 멤버 변수에 코루틴 고유 리턴값 저장

        this.coChargeJumpPower = this.StartCoroutine(this.ChargeJumpPower());

        // ========== 추가

    }


    // 버튼에서 손을 떼었을 때 호출될 함수 선언

    btnJumpUp() {

        // ========== 추가

        // ClientScript 인스턴스 추출

        const clientScript = ClientScript.GetInstance();

        // 점프력 ZepetoPlayers 오브젝트의 캐릭터 jumpPower 속성에 반영

        clientScript.objZepetoPlayers.characterData.jumpPower = this.jumpPower;

        // 코루틴 고유 리턴값을 활용하여 실행시켰던 점프력 충전 코루틴 중지

        this.StopCoroutine(this.coChargeJumpPower);

        // ========== 추가

        // 점프 함수 실행

        this.StartCoroutine(this.Jump());

    }


    /** 캐릭터가 다음 블록을 향해 점프하도록 하는 함수 */

    private *Jump() {

        // 점프할 캐릭터의 플레이어 정보가 저장되어 있는 ClientScript 불러오기

        const character = ClientScript.GetInstance().players.get(`LocalPlayer`).character;

        // 플레이어 점프 시키기

        character.Jump();

        yield new WaitForSeconds(0.1);

        character.MoveContinuously(new Vector3(1, 0, 1));

        // 점프 상태임을 저장

        this.isJumping = true;

    }


}




취소
 공유
취소
댓글 0
댓글 알림
나의얼굴