using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.XR.Interaction.Toolkit; public class TeleportationController : MonoBehaviour { public InputActionProperty m_teleportModeActivate; public InputActionProperty m_teleportModeCancel; private InputAction teleportModeActivate; private InputAction teleportModeCancel; public XRRayInteractor teleportInteractor; void Start() { teleportModeActivate = m_teleportModeActivate.action; teleportModeCancel = m_teleportModeCancel.action; EnableAction(); } private void OnDestroy() { DisableAction(); } void Update() { if (CanEnterTeleport()) { SetTeleportController(true); return; } if (CanExitTeleport()) { SetTeleportController(false); return; } } private void SetTeleportController(bool isEnable) { if (teleportInteractor != null) { teleportInteractor.gameObject.SetActive(isEnable); } } private bool CanEnterTeleport() { bool isTriggerTeleport = teleportModeActivate != null && teleportModeActivate.triggered; bool isCancelTeleport = teleportModeCancel != null && teleportModeCancel.triggered; return isTriggerTeleport && !isCancelTeleport; //判断是否触发传送且没有按下取消传送的键 } private bool CanExitTeleport() { bool isCancelTeleport = teleportModeCancel != null && teleportModeCancel.triggered; bool isReleaseTeleport = teleportModeActivate != null && teleportModeActivate.phase == InputActionPhase.Waiting; return isCancelTeleport || isReleaseTeleport; //判断是否按下取消传送的键或者释放了之前推动的摇杆 } private void EnableAction() { if (teleportModeActivate != null && teleportModeActivate.enabled) { teleportModeActivate.Enable(); } } private void DisableAction() { if (teleportModeActivate != null && teleportModeActivate.enabled) { teleportModeActivate.Disable(); } } }
您需要 登录 才可以下载或查看,没有账号?立即注册
使用道具 举报
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )
GMT+8, 2024-11-16 06:34 , Processed in 0.065481 second(s), 23 queries .
Powered by Discuz! X3.5 Licensed
© 2001-2024 Discuz! Team.