Tanoda
VRCursor.cs
Go to the documentation of this file.
1
3
5{
6 [AddComponentMenu("UI/Extensions/VR Cursor")]
7 public class VRCursor : MonoBehaviour
8 {
9 public float xSens;
10 public float ySens;
11
12 private Collider currentCollider;
13
14 // Update is called once per frame
15 void Update()
16 {
17 Vector3 thisPosition;
18
19 thisPosition.x = Input.mousePosition.x * xSens;
20 thisPosition.y = Input.mousePosition.y * ySens - 1;
21 thisPosition.z = transform.position.z;
22
23 transform.position = thisPosition;
24
25 VRInputModule.cursorPosition = transform.position;
26
27 if (Input.GetMouseButtonDown(0) && currentCollider)
28 {
29 VRInputModule.PointerSubmit(currentCollider.gameObject);
30 }
31
32 }
33
34 void OnTriggerEnter(Collider other)
35 {
36 //print("OnTriggerEnter other " + other.gameObject);
37 VRInputModule.PointerEnter(other.gameObject);
38 currentCollider = other;
39 }
40
41 void OnTriggerExit(Collider other)
42 {
43 //print("OnTriggerExit other " + other.gameObject);
44 VRInputModule.PointerExit(other.gameObject);
45 currentCollider = null;
46 }
47 }
48}
static void PointerSubmit(GameObject obj)
static void PointerEnter(GameObject obj)
Credit Erdener Gonenc - @PixelEnvision.