สร้างโลกของคุณเอง
ผู้เล่นและตัวละคร: เคล็ดลับ
ตรวจสอบว่าตัวละครอยู่บนพื้นหรือไม่
5นาที
ในคู่มือนี้ เราจะแสดงให้คุณเห็นว่าคุณจะตรวจสอบได้อย่างไรว่า ตัวละคร zepeto ของผู้เล่นท้องถิ่นอยู่บนพื้นหรือไม่ โดยอิงจาก isgrounded ฟังก์ชันที่จัดเตรียมโดย unity 📘 charactercontroller isgrounded https //docs unity3d com/scriptreference/charactercontroller isgrounded html https //docs unity3d com/scriptreference/charactercontroller isgrounded html ขั้นตอนที่ 1 เขียนสคริปต์ เพิ่ม gameobject ลงในฉากและเพิ่มสคริปต์ตัวอย่าง isgrounded ด้านล่างนี้ import { zepetoscriptbehaviour } from 'zepeto script' import { zepetoplayers } from 'zepeto character controller'; import { text } from 'unityengine ui'; export default class isgrounded extends zepetoscriptbehaviour { public mytext text; update() { // เข้าถึงตัวควบคุมตัวละครของผู้เล่นท้องถิ่น const localcharacter = zepetoplayers instance localplayer zepetoplayer character charactercontroller; // ตรวจสอบว่าตัวควบคุมตัวละครสัมผัสกับ collider อื่นหรือไม่ โดยใช้ isgrounded if (localcharacter isgrounded) { this mytext text = "ตัวละครอยู่บนพื้น"; } else { this mytext text = "ตัวละครไม่ได้อยู่บนพื้น"; } } } ขั้นตอนที่ 2 ตั้งค่า text ui เพิ่ม ui > ข้อความลงในฉาก ในหน้าต่าง hierachy เชื่อมต่อ canvas > ส่วนประกอบข้อความกับคุณสมบัติที่แสดงในหน้าต่าง zepetoscript inspector โดยการลากและวาง ขั้นตอนที่ 3 รัน หากคุณกดปุ่มเล่นเพื่อรัน คุณสามารถตรวจสอบได้ว่าตัวละครอยู่บนพื้นหรือไม่ผ่าน ui ข้อความ