-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerrainDeformerInput.cs
More file actions
62 lines (50 loc) · 1.33 KB
/
TerrainDeformerInput.cs
File metadata and controls
62 lines (50 loc) · 1.33 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TerrainDeformerInput : MonoBehaviour {
private TerrainDeformer deformer;
private bool deform = false;
private Vector3 point;
[SerializeField]
private Leap.Unity.PinchDetector[] pinchDetectors;
void Awake(){
if (pinchDetectors.Length == 0) {
Debug.LogWarning("No pinch detectors were specified! PinchDraw can not draw any lines without PinchDetectors.");
}
}
void Update() {
for (int i = 0; i < pinchDetectors.Length; i++) {
var detector = pinchDetectors [i];
if (detector.DidStartHold) {
Debug.Log ("Started pinch");
HandlePinchInput (detector);
}
else if (detector.DidRelease) {
Debug.Log ("Finished pinch");
deform = false;
deformer = null;
numOfPoints = 0;
iterator = 0;
}
else if (detector.IsHolding) {
Debug.Log ("Holding pinch");
PinchMove (detector);
}
}
}
void HandlePinchInput(Leap.Unity.PinchDetector detector){
RaycastHit hit;
if(Physics.Raycast(detector.Position, Vector3.down, out hit)){
deformer = hit.collider.GetComponent<TerrainCollider>();
}
if(deformer){
deform = true;
point = hit.point;
}
}
void PinchMove(Leap.Unity.PinchDetector detector){
if (deform) {
Vector3 pointOfAttack = detector.Position - Vector3.down * 0.1f;
}
}
}