TUTORIAL
Dunia acak sederhana menggunakan interaksi
6mnt
proyek contoh 📘 berkas proyek yang digunakan dalam kuliah https //github com/naverz/zepeto world sample/tree/main/assets/chapter3 https //github com/naverz/zepeto world sample/tree/main/assets/chapter3 ringkasan ringkasan implementasikan tombol interaksi yang muncul ketika pengguna mendekati anda kesulitan pemula waktu yang diperlukan 30 menit tujuan proyek kontrol tombol interaktif menerapkan ui dan pemicu kanvas ruang dunia terapkan animasi karakter membuat instansi objek terapkan kode acak probabilitas 🎬 video dunia yang selesai https //www youtube com/watch?v=ooazdb4 lgo https //www youtube com/watch?v=ooazdb4 lgo skrip charactercontroller ts import { zepetoscriptbehaviour } from 'zepeto script' import { spawninfo, zepetoplayers, localplayer, zepetocharacter } from 'zepeto character controller' import { worldservice } from 'zepeto world'; export default class charactercontroller extends zepetoscriptbehaviour { start() { //mengambil userid (masuk melalui editor) zepetoplayers instance createplayerwithuserid(worldservice userid,new spawninfo(), true); zepetoplayers instance onaddedlocalplayer addlistener(() => { let player localplayer = zepetoplayers instance localplayer; }); } } interaction ts import { canvas, animationclip, waitforseconds, gameobject, object, random } from 'unityengine'; import { button } from 'unityengine ui'; import { zepetoplayers, zepetocharacter } from 'zepeto character controller'; import { zepetoscriptbehaviour } from 'zepeto script'; // import skrip kustom dari jalur import uicontroller from ' /uicontroller'; export default class interaction extends zepetoscriptbehaviour { public openuigesture button; public interactioncanvas canvas; public animationclip animationclip; public uicontrollerobject gameobject; public badeffectfactory gameobject; public goodeffectfactory gameobject; public gift gameobject; public failureratio number = 50; private uicontroller uicontroller; private zepetocharacter \ zepetocharacter; start() { // set eventcamera this interactioncanvas worldcamera = zepetoplayers instance zepetocamera camera; // set karakter zepetoplayers instance onaddedlocalplayer addlistener(() => { this zepetocharacter = zepetoplayers instance localplayer zepetoplayer character; }); // impor skrip this uicontroller = this uicontrollerobject getcomponent\<uicontroller>(); //tombol sembunyikan this openuigesture gameobject setactive(false); //ketika tombol diklik this openuigesture onclick addlistener(()=>{ this zepetocharacter setgesture(this animationclip); this startcoroutine(this firstroutine()); }); } ontriggerenter(collider) { this openuigesture gameobject setactive(true); } ontriggerexit(collider) { this openuigesture gameobject setactive(false); } firstroutine() { this uicontroller loading(); yield new waitforseconds(3); this zepetocharacter cancelgesture(); this randomcalculation(); } private randomcalculation() { let randomnumber number; randomnumber = random range(0,100); if (randomnumber <= this failureratio) { this lose(); } else { this win(); } this startcoroutine(this secondroutine()); } private lose() { this uicontroller lose(); //buat gameobject var obj = object instantiate(this badeffectfactory) as gameobject; obj transform position = this transform position; } private win() { this uicontroller win(); //buat gameobject var obj = object instantiate(this goodeffectfactory) as gameobject; obj transform position = this transform position; var giftobj = object instantiate(this gift) as gameobject; giftobj transform position = this transform position; } secondroutine() { yield new waitforseconds(1); this uicontroller init(); //hancurkan kotak gameobject destroy(this gameobject); } } uicontroller ts import { zepetoscriptbehaviour } from 'zepeto script'; import { text } from "unityengine ui"; import { gameobject } from 'unityengine'; //define variable to use export default class uicontroller extends zepetoscriptbehaviour { public messageui text; start() { this init(); } public init() { this messageui text = " "; } public loading() { this messageui text = "apa yang ada di dalam kotak?"; } public win() { this messageui text = "selamat! anda mendapatkannya"; } public lose() { this messageui text = "ini kosong"; } }