Last active
August 29, 2015 14:26
-
-
Save zorawar87/57e1b4e350dcf9d3f19e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using Leap; | |
public class Instantiation : MonoBehaviour { | |
//public Rigidbody projectile; | |
public GameObject projectile; | |
public int limiter=5; | |
Controller controller; | |
//Rigidbody clone; | |
void Start(){ | |
controller = new Controller(); | |
/*controller.EnableGesture(Gesture.GestureType.TYPE_SWIPE); | |
controller.Config.SetFloat("Gesture.Swipe.MinLength", 20.0f); | |
controller.Config.SetFloat("Gesture.Swipe.MinVelocity", 50f); | |
controller.Config.Save();*/ | |
} | |
void Update() { | |
//Leap Motion code | |
Frame frame = controller.Frame(); // controller is a Controller object | |
HandList hands = frame.Hands; | |
Hand rhand = frame.Hands.Rightmost; | |
Hand lhand = frame.Hands.Leftmost; | |
//Normal code | |
Debug.Log ("start"); | |
if (rhand.IsValid && lhand.IsValid) { | |
if (rhand.IsRight) { | |
Debug.Log ("Right Hand"); | |
isRH (rhand); | |
} else if (lhand.IsLeft) { | |
Debug.Log ("LEft Hand"); | |
isLH (lhand); | |
} else{ | |
Debug.Log ("MOTHER OF GOD HOW MANY HANDS DO YOU HAVE?"); | |
} | |
} else { | |
Debug.Log("leap says fu"); | |
} | |
} | |
void isRH(Hand rhand){ | |
//Instantiate (projectile, position, transform.rotation); | |
//CloneCode | |
GameObject[] clones = GameObject.FindGameObjectsWithTag("Clone"); | |
if (clones.Length < limiter) { | |
Debug.Log ("RHClone"); | |
//Vector3 position = new Vector3 (rhand.PalmNormal.x, rhand.PalmNormal.y, rhand.PalmNormal.z); | |
for (int i=0; i<=clones.Length;i++){ | |
Vector3 position = new Vector3 (rhand.PalmPosition.x/1000, rhand.PalmPosition.y/1000, rhand.PalmPosition.z/1000); //PalmNormal or PalmPosition | |
//Vector3 position = new Vector3 (rhand.PalmPosition.z/1000, 0, rhand.PalmPosition.x/1000); //PalmNormal or PalmPosition | |
//Vector3 position = new Vector3 (-rhand.PalmPosition.z/1000, 0, 00); //PalmNormal or PalmPosition | |
//Vector3 position = new Vector3 (-rhand.PalmPosition.z/1000, 0, 00); //PalmNormal or PalmPosition | |
position= transform.TransformPoint(position); | |
Debug.Log ("Defpos"+rhand.PalmPosition); | |
Debug.Log ("PalmPos"+position); | |
if(i != 0){ | |
Debug.Log("i!=0"); | |
if ( | |
(clones[i].transform.position.x <= clones[i-1].transform.position.x *1.5f) || | |
(clones[i].transform.position.y <= clones[i-1].transform.position.y *1.5f) || | |
(clones[i].transform.position.z <= clones[i-1].transform.position.z *1.5f) | |
){ | |
Debug.Log ("Shouldn't work"); | |
} | |
} else{ | |
Debug.Log("Instant"); | |
Instantiate (projectile, position, transform.rotation); | |
} | |
} | |
Debug.Log ("done"); | |
}else{ | |
Debug.Log ("fail"+GameObject.FindGameObjectsWithTag("Clone").Length); | |
for(int i=0; i<limiter;i++){ | |
Destroy(GameObject.FindGameObjectWithTag("Clone")); | |
} | |
} | |
} | |
void isLH(Hand lhand){ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment