示例
两块内容:进入区域就把本地玩家传送到目的地,以及区域里显示在线人数。前者是很多”门/电梯/传送门”脚本的基础。
using UnityEngine;
using Cilbox;
using Aeloria.Scripts.AeloriaSdk.Players;
[Cilboxable]
public class ZoneTeleport : MonoBehaviour
{
public Transform destination;
void OnTriggerEnter(Collider other)
{
// 只处理本地玩家(Player 层是 3,见「场景层级」)
if (other.gameObject.layer != 3) return;
AeloriaLocalPlayer local = AeloriaLocalPlayer.Instance;
if (local == null) return;
local.Teleport(destination.position, destination.rotation, mode: AeloriaTeleportMode.WorldFeet);
}
}
OnTriggerEnter 只会在物体进入的瞬间触发一次,所以不会每帧被传送;如果目的地就在触发区里,记得把它放远一点,避免来回传送。
显示”当前在线”比逐个统计区域更简单,也够大多数大厅用:
using UnityEngine;
using Cilbox;
using TMPro;
using Aeloria.Shims;
[Cilboxable]
public class LobbyCount : MonoBehaviour
{
public TextMeshProUGUI label;
float nextUpdate;
void Update()
{
if (Time.time < nextUpdate) return;
nextUpdate = Time.time + 0.5f;
label.text = AeloriaPlayersShim.Count.ToString();
}
}
两块都可以放在世界/道具里;传送在形象脚本里也能用,但形象沙盒里做传送没有实际意义。