12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using Valve.VR;
- using Valve.VR.Extras;
- using Valve.VR.InteractionSystem;
- public class UIInteraction : MonoBehaviour
- {
- public static GameObject curentObject;
- public Hand TargetSource;
- public SteamVR_Action_Boolean ClickAction;
- public EventSystem system;
- int currID;
- private SteamVR_LaserPointer pointer;
- // Start is called before the first frame update
- void Start()
- {
- curentObject = null;
- currID = 0;
- pointer = GetComponent<SteamVR_LaserPointer>();
- }
- // Update is called once per frame
- void Update()
- {
- if (TargetSource.currentAttachedObject != null)
- {
- pointer.holder.SetActive(false);
- }
- else
- {
- pointer.holder.SetActive(true);
- }
- if (ClickAction.GetStateDown(TargetSource.handType) && pointer.active)
- {
- RaycastHit[] hits;
- hits = Physics.RaycastAll(transform.position, transform.forward, 0.25f);
- for (int i = 0; i < hits.Length; i++)
- {
- RaycastHit hit = hits[i];
- int id = hit.collider.gameObject.GetInstanceID();
- if (currID != id)
- {
- //currID = id;
- curentObject = hit.collider.gameObject;
- ExecuteEvents.Execute(curentObject, new BaseEventData(system), ExecuteEvents.submitHandler);
- Debug.Log("pressed stuff");
- }
- }
- }
- }
- }
|