/
DropCube.cs
31 lines (27 loc) · 1.02 KB
/
DropCube.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
using UnityEngine;
using UnityEngine.VR.WSA.Input;
/// <summary>
/// Simple test script for dropping cubes with physics to observe interactions
/// </summary>
public class DropCube : MonoBehaviour
{
GestureRecognizer recognizer;
void Start ()
{
recognizer = new GestureRecognizer();
recognizer.SetRecognizableGestures(GestureSettings.Tap);
recognizer.TappedEvent += Recognizer_TappedEvent;
recognizer.StartCapturingGestures();
}
void OnDestroy()
{
recognizer.TappedEvent -= Recognizer_TappedEvent;
}
private void Recognizer_TappedEvent(InteractionSourceKind source, int tapCount, Ray headRay)
{
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube); // Create a cube
cube.transform.localScale = Vector3.one * 0.3f; // Make the cube smaller
cube.transform.position = Camera.main.transform.position + Camera.main.transform.forward; // Start to drop it in front of the camera
cube.AddComponent<Rigidbody>(); // Apply physics
}
}