-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectGrabOnHover.cs
More file actions
39 lines (37 loc) · 1.19 KB
/
DirectGrabOnHover.cs
File metadata and controls
39 lines (37 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
public class DirectGrabOnHover : MonoBehaviour
{
private XRRayInteractor Ray;
private float originalMax;
private int grabLayer;
private XRInteractorLineVisual line;
private float originalLength;
// Start is called before the first frame update
void Start()
{
Ray = GetComponent<XRRayInteractor>();
originalMax = Ray.maxRaycastDistance;
grabLayer = LayerMask.NameToLayer("Grab");
line = GetComponent<XRInteractorLineVisual>();
originalLength = line.lineLength;
}
// Update is called once per frame
void Update()
{
if (Physics.Raycast(transform.position, transform.forward, out var hit, Mathf.Infinity, 1 << grabLayer))
{
Debug.Log("Changed to grab distance");
Ray.maxRaycastDistance = 0.3f;
line.lineLength = 0;
}
else
{
Debug.Log("Changed to original distance");
Ray.maxRaycastDistance = originalMax;
line.lineLength = originalLength;
}
}
}