/
wavehelloOrion.cs
executable file
·98 lines (67 loc) · 2.73 KB
/
wavehelloOrion.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using UnityEngine;
using System.Collections;
using Leap;
// This script is for the waving hello project using Orion.
// http://rifty-business.blogspot.com/
// Copyright: Karen Bryla (karen@karenbryla.com)
public class wavehelloOrion : MonoBehaviour
{
LeapProvider provider;
Animator anim;
GameObject speechbubble;
GameObject centerEyeAnchor;
// Use this for initialization
void Start()
{
provider = FindObjectOfType<LeapProvider>() as LeapProvider;
anim = GetComponent<Animator>();
speechbubble = GameObject.Find("speechbubble");
centerEyeAnchor = GameObject.Find("CenterEyeAnchor");
}
// Update is called once per frame
void Update()
{
// Get the current frame.
Frame frame = provider.CurrentFrame;
// The frame conatins all the hands found. To simplify things a bit, the script only looks at the
// right hand to see if it is waving. (That way, the script does not need to account for one hand up
// and one hand down). The hands Y value is then compared to the Y value of the CenterEyeAncho.
// The CenterEyeAnchor object is located at the center of the user's eyes. If the Y value of
// the hand is greater than y value of the centerEyeAnchor, the hand is raised
// above the eyes. If the hand is above the eyes, set the trigger to wave and display the speech bubble.
foreach (Hand hand in frame.Hands)
{
if (hand.IsRight)
{
if (hand.PalmPosition.y >= centerEyeAnchor.transform.position.y - 0.03f)
{
anim.SetTrigger("Wave");
changeMenuDisplay(speechbubble, 1);
Debug.Log("Hand above");
}
else
{
anim.SetTrigger("Idle");
changeMenuDisplay(speechbubble, 0);
Debug.Log("Hand below");
}
}
}
}
void changeMenuDisplay(GameObject menu, float alphavalue)
{
Transform tempcanvas = menu.transform;
if (tempcanvas != null)
{
CanvasGroup[] cg;
cg = tempcanvas.gameObject.GetComponents<CanvasGroup>();
if (cg != null)
{
foreach (CanvasGroup cgs in cg)
{
cgs.alpha = alphavalue;
}
}
}
}
}