-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCWVRPointer.cs
65 lines (58 loc) · 1.86 KB
/
CWVRPointer.cs
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Part of the CWVRGUI system -- github.com/chilton/CWVRGUI
// Attach this to some object you want to use as your controller.
// A camera will be automatically added. Disable the camera component, but leave it on the object.
// Attach the CWVRCanvas object to your World Space based canvas.
// Then drag that object onto this one's list of canvases.
// if you want to test whether or not this works, point this object at a buttton that canvas while playing.
// Make sure the DebugX bool is true
// Make sure the Game view is active
// Tap the letter X on your keyboard.
// The button should be activated.
//
// License and Restrictions: This is covered by the MIT license.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Camera))]
public class CWVRPointer : MonoBehaviour
{
public Camera myCamera;
public CWVRCanvas[] canvases;
public bool autoPowerUp = true;
public bool DebugX = false;
// Start is called before the first frame update
void Start()
{
//myCamera = GetComponent<Camera>(); // This works if you have your camera component enabled.
myCamera.enabled = false;
if (autoPowerUp==true) {
PowerUp();
}
}
// Update is called once per frame
void PowerUp()
{
// find all the CWVRCanvases and send them our pointer.
for (int i = 0; i < canvases.Length; i++)
{
canvases[i].SetCamera(myCamera);
}
}
public void ClickCanvas()
{
for (int i = 0; i < canvases.Length; i++)
{
canvases[i].Click();
}
}
private void Update()
{
if (DebugX == true)
{
if (Input.GetKeyUp(KeyCode.X))
{
ClickCanvas();
}
}
}
}