Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.XR.Interaction.Toolkit;
- public class CardReader : XRSocketInteractor
- {
- private bool m_SwipeIsValid = false;
- private Vector3 m_HoverEntry;
- public float AllowedUprightErrorRange = 0.1f;
- public GameObject visualLockToHide;
- //public bool handleToEnable ; // Handle this after you complete the CardReader
- public float minDisThroughReader = -0.15f;
- private KeyDetector keyDetector;
- public GameObject m_KeycardGameObject;
- public Transform m_KeycardTransform;
- protected override void OnHoverEntered(HoverEnterEventArgs args)
- {
- base.OnHoverEntered(args);
- keyDetector.iKeycard = m_KeycardGameObject; // Can't seem to figure out how to reference an instantiated GameObject(iKeycard)
- // from the KeyDetector script????
- m_KeycardTransform = m_KeycardGameObject.transform.position;
- m_KeycardTransform = args.interactableObject.transform;
- m_HoverEntry = m_KeycardTransform.position;
- m_SwipeIsValid = true;
- Debug.Log("Hover has been entered");
- }
- protected override void OnHoverExited(HoverExitEventArgs args)
- {
- base.OnHoverExited(args);
- Vector3 entryToExit = m_KeycardTransform.position - m_HoverEntry;
- if (m_SwipeIsValid && entryToExit.y < minDisThroughReader)
- {
- visualLockToHide.gameObject.SetActive(false);
- //handleToEnable.enabled = true; // // Handle this after you complete the CardReader
- }
- m_KeycardTransform = null;
- }
- private void Update()
- {
- if (m_KeycardTransform != null)
- {
- Vector3 keycardUp = m_KeycardTransform.forward;
- float dot = Vector3.Dot(keycardUp, Vector3.up);
- if (dot < 1 - AllowedUprightErrorRange)
- {
- m_SwipeIsValid = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement