You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
6 months ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.InputSystem;
|
||
|
using UnityEngine.XR;
|
||
|
|
||
|
namespace Autohand.Demo{
|
||
|
public class OpenXRTeleporterLink : MonoBehaviour{
|
||
|
public Teleporter hand;
|
||
|
public InputActionProperty startTeleportAction;
|
||
|
public InputActionProperty finishTeleportAction;
|
||
|
|
||
|
bool teleporting = false;
|
||
|
|
||
|
void OnEnable() {
|
||
|
if(startTeleportAction.action != null) startTeleportAction.action.Enable();
|
||
|
if (startTeleportAction.action != null) startTeleportAction.action.performed += StartTeleportAction;
|
||
|
if (finishTeleportAction.action != null) finishTeleportAction.action.Enable();
|
||
|
if (finishTeleportAction.action != null) finishTeleportAction.action.performed += FinishTeleportAction;
|
||
|
}
|
||
|
|
||
|
void OnDisable() {
|
||
|
if (startTeleportAction.action != null) startTeleportAction.action.performed -= StartTeleportAction;
|
||
|
if (finishTeleportAction.action != null) finishTeleportAction.action.performed -= FinishTeleportAction;
|
||
|
}
|
||
|
|
||
|
|
||
|
void StartTeleportAction(InputAction.CallbackContext a) {
|
||
|
if(!teleporting){
|
||
|
hand.StartTeleport();
|
||
|
teleporting = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void FinishTeleportAction(InputAction.CallbackContext a) {
|
||
|
if(teleporting){
|
||
|
hand.Teleport();
|
||
|
teleporting = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|