CREATE YOUR WORLD
Players & Characters: Tips
Hide and Show ZEPETO Character Appearance
4 min
using renderer method you can disable the zepeto character's renderer to make it invisible to the camera the following is an example code to hide and show the character's appearance with the press of a button 1\) create a hierarchy > create empty object and rename it to hideshowcharacter 2\) create project > create > zepeto > typescript and rename it to hideshowcharacter 3\) add a script to the hideshowcharacter object 4\) write the sample script as shown below hideshowcharacter import { renderer } from 'unityengine'; import { button } from 'unityengine ui'; import { spawninfo, zepetoplayers } from 'zepeto character controller'; import { zepetoscriptbehaviour } from 'zepeto script'; export default class hideshowcharacter extends zepetoscriptbehaviour { public hidecharacterbtn button; public showcharacterbtn button; start() { zepetoplayers instance onaddedlocalplayer addlistener(() => { this hidecharacterbtn onclick addlistener(() => { // disable the renderer of the zepeto character to make it invisible to the camera zepetoplayers instance localplayer zepetoplayer character getcomponentsinchildren\<renderer>() foreach(r => { r enabled = false; console log("hide"); }); }); this showcharacterbtn onclick addlistener(() => { zepetoplayers instance localplayer zepetoplayer character getcomponentsinchildren\<renderer>() foreach(r => { r enabled = true; console log("show"); }); }); }); } } 5\) use canvas > button to add each button to the screen and assign them to the script inspector 6\) press the \[▶︎(play)] button to run it change the character's layer to handle hiding in addition to disabling the character's renderer, you can also hide and show the character's appearance this is done by utilizing the culling mask in the zepeto camera the culling mask allows you to treat specific layers as invisible when a zepeto character is created, there are no layers set by default the following example code shows how to make a specific layer invisible in the zepeto camera, and then change the layer of the zepeto character at the click of a button to hide and show it import { zepetoscriptbehaviour } from 'zepeto script'; import { camera, layermask, transform } from "unityengine"; import { zepetocharacter, zepetoplayers } from "zepeto character controller"; import { button } from "unityengine ui"; // a function that changes the layer of all sub objects of a character function changelayersrecursively(transform transform, layer string, fromlayer? string) void { if (!transform || !layer || layer length === 0) { return; } if (fromlayer) { if (transform gameobject layer === layermask nametolayer(fromlayer)) { transform gameobject layer = layermask nametolayer(layer); } } else { transform gameobject layer = layermask nametolayer(layer); } for (let i = 0; i < transform childcount; i++) { let child = transform getchild(i); changelayersrecursively(child, layer, fromlayer); } } export default class changecameralayer extends zepetoscriptbehaviour { private zepetocamera camera; public hidecharacterbtn button; public showcharacterbtn button; start() { zepetoplayers instance onaddedlocalplayer addlistener(() => { let character = zepetoplayers instance localplayer zepetoplayer character; this zepetocamera = zepetoplayers instance localplayer zepetocamera camera; // add layer to culling mask this zepetocamera cullingmask |= (1 << layermask nametolayer("player")); // remove layer from culling mask this zepetocamera cullingmask &= (1 << layermask nametolayer("transparentfx")); this hidecharacterbtn onclick addlistener(() => { this sethiddenlayer(character); }); this showcharacterbtn onclick addlistener(() => { this setplayerlayer(character); }); }); } setplayerlayer(playerobject zepetocharacter) { changelayersrecursively(playerobject transform, "player"); } sethiddenlayer(playerobject zepetocharacter) { changelayersrecursively(playerobject transform, "transparentfx"); } }