TUTORIALS
Simple random world using interaction
6min
sample project 📘 project files used in lecture https //github com/naverz/zepeto world sample/tree/main/assets/chapter3 https //github com/naverz/zepeto world sample/tree/main/assets/chapter3 summary summary implement the interaction buttons that appear when the user approaches you difficulty beginner time required 30 minutes project goals interactive button controls applying ui and trigger world space canvas apply character animation creating an object instance apply probability random code 🎬 video of completed world https //www youtube com/watch?v=ooazdb4 lgo https //www youtube com/watch?v=ooazdb4 lgo scripts 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() { //gets the userid (logged in through 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 custom script from path 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 character zepetoplayers instance onaddedlocalplayer addlistener(() => { this zepetocharacter = zepetoplayers instance localplayer zepetoplayer character; }); // script import this uicontroller = this uicontrollerobject getcomponent\<uicontroller>(); //button hide this openuigesture gameobject setactive(false); //when button click 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(); //gameobject create var obj = object instantiate(this badeffectfactory) as gameobject; obj transform position = this transform position; } private win() { this uicontroller win(); //gameobject create 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(); //destroy box 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 = "what is in the box?"; } public win() { this messageui text = "congrats! you got it"; } public lose() { this messageui text = "it's a blank"; } }