-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spells.cs
72 lines (58 loc) · 2.48 KB
/
Spells.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
66
67
68
69
70
71
72
using UnityEngine;
using System.Collections;
using Leap;
using System.Collections.Generic;
using Leap.Unity;
public class Spells : MonoBehaviour
{
Leap.Controller controller;
// Use this for initialization
void Start()
{
controller = new Controller();
}
// Update is called once per frame
float nextFire = 0.0f;
void Update()
{
Frame frame = controller.Frame();
if (frame.Hands.Count > 0)
{
List<Hand> hands = frame.Hands;
Hand firstHand = hands[0];
Finger thumb = frame.Hands[0].Fingers
[(int)Finger.FingerType.TYPE_THUMB];
Finger index = frame.Hands[0].Fingers
[(int)Finger.FingerType.TYPE_INDEX];
Finger middle = frame.Hands[0].Fingers
[(int)Finger.FingerType.TYPE_MIDDLE];
Finger ring = frame.Hands[0].Fingers
[(int)Finger.FingerType.TYPE_RING];
Finger pinky = frame.Hands[0].Fingers
[(int)Finger.FingerType.TYPE_PINKY];
if (Time.time > nextFire && firstHand.IsRight)
{
Vector position = firstHand.PalmPosition/1000;
bool extended = thumb.IsExtended && index.IsExtended && middle.IsExtended && ring.IsExtended && pinky.IsExtended;
if (extended)
{
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.GetComponent<Renderer>().material.color = Color.red;
sphere.transform.position = position.ToVector3();
Vector3 scale = transform.localScale;
scale.x = 0.2f;
scale.y = 0.2f;
scale.z = 0.2f;
sphere.transform.localScale = scale;
Rigidbody sphereRigid = sphere.AddComponent<Rigidbody>().GetComponent<Rigidbody>();
sphereRigid.mass = 1f;
sphereRigid.useGravity = false;
Vector3 direct = new Vector3(firstHand.PalmNormal.ToVector3().x, firstHand.PalmNormal.ToVector3().y, -firstHand.PalmNormal.ToVector3().z);
sphereRigid.AddForce(transform.TransformVector(direct)*500);
Destroy(sphere, 3f);
nextFire = Time.time + 1.0f;
}
}
}
}
}