-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFight.cs
66 lines (58 loc) · 1.51 KB
/
Fight.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
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
public class Fight : MonoBehaviour {
public Texture2D punch1;
public Texture2D punch2;
public Texture2D nowPunch;
public Texture2D punchSuccess;
public float secondsPerFrame;
public float frames;
public float punchGForce;
private ThalmicMyo myo;
private Texture2D punch;
private float startTime;
private bool punched;
public int enemyHealth = 3;
void Start () {
myo = GameObject.Find("Myo").GetComponent<ThalmicMyo> ();
startTime = Time.time;
}
void OnGUI () {
if (Time.time - startTime < frames * secondsPerFrame) {
if (Mathf.RoundToInt ((Time.time - startTime) / secondsPerFrame) % 2 == 1) {
punch = punch2;
} else {
punch = punch1;
}
} else {
if (Mathf.Abs(myo.accelerometer.z) > punchGForce && enemyHealth > 0) {
enemyHealth = enemyHealth - 1;
//Debug.Log ("Calling GUI");
//Debug.Log ("Success");
StartCoroutine (delay ());
}
}
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), punch);
}
IEnumerator delay () {
myo.Vibrate (Thalmic.Myo.VibrationType.Short);
yield return new WaitForSeconds (1);
Debug.Log ("Delayed 1 second");
yield return null;
Application.LoadLevel(4);
}
/*void FixedUpdate () {
if (myo.pose == Thalmic.Myo.Pose.Fist) {
Debug.Log ("GET READY TO RUMBLE");
}
if (myo.accelerometer.z > 0.5) {
Debug.Log("YOU PUNCHED");
}
}*/
}