// Update is called once per frame void Update() { if (MagicRoomKinectV2Manager.instance.MagicRoomKinectV2Manager_active) { temporarySkeleton = null; foreach (KinectBodySkeleton c in MagicRoomKinectV2Manager.instance.skeletons) { //Debug.Log(c); if (temporarySkeleton == null && c.SpineBase.z > 0) { temporarySkeleton = c; } else if (temporarySkeleton == null) { continue; } else if (temporarySkeleton.SpineBase.z > c.SpineBase.z && c.SpineBase.z > 0) { temporarySkeleton = c; } } skeleton = temporarySkeleton; RaycastHit2D hitRight = Physics2D.Raycast(new Vector2((skeleton.HandRight.x * 9f), (skeleton.HandRight.y * 5f)), Vector2.zero); RaycastHit2D hitLeft = Physics2D.Raycast(new Vector2((skeleton.HandLeft.x * 9f), (skeleton.HandLeft.y * 5f)), Vector2.zero); if (feet) { timePassed += Time.deltaTime; if (((skeleton.SpineBase.x + 0.7f) * 6.35f) + 14.2f < feetObject.GetComponent <Transform>().position.x + 1.5f && ((skeleton.SpineBase.x + 0.7f) * 6.35f) + 14.2f > feetObject.GetComponent <Transform>().position.x - 1.5) { onthefeet = true; onFeet += Time.deltaTime; //MagicRoomLightManager.instance.sendColour(Color.green, 40); notOnFeet = 0; } else { onFeet = 0; notOnFeet += Time.deltaTime; onthefeet = false; } if (notOnFeet > 2) { MagicRoomLightManager.instance.sendColour(Color.red, 100); notOnFeet = 0; } if (onFeet > 2) { MagicRoomLightManager.instance.sendColour(Color.blue, 40); onFeet = 0; } if (timePassed > 15f) { feetObject.GetComponent <Transform>().position = new Vector3(UnityEngine.Random.Range(16, 23), -1.8f); timePassed = 0; MagicRoomLightManager.instance.sendColour(Color.red, 40); onFeet = 1; } } if (hitRight.collider != null && skeleton.isRightHandClosed(0.07f) && onlyOneRight && onthefeet) { clickedRight = hitRight.transform.gameObject; clickedRight.GetComponent <Movement>().follow = true; clickedRight.GetComponent <Rigidbody2D>().isKinematic = false; clickedRight.GetComponent <Movement>().follow_x = skeleton.HandRight.x * 9f; clickedRight.GetComponent <Movement>().follow_y = skeleton.HandRight.y * 5f; colorRight = clickedRight.GetComponent <Renderer>().material.GetColor("_Color"); clickedRight.GetComponent <Renderer>().material.SetColor("_Color", Color.gray); onlyOneRight = false; } else if (clickedRight != null) { clickedRight.GetComponent <Movement>().follow = false; clickedRight.GetComponent <Renderer>().material.SetColor("_Color", Color.white); clickedRight.GetComponent <Rigidbody2D>().isKinematic = true; onlyOneRight = true; } else { onlyOneRight = true; } if (hitLeft.collider != null && skeleton.isLeftHandClosed(0.07f) && onlyOneLeft && onthefeet) { clickedLeft = hitLeft.transform.gameObject; clickedLeft.GetComponent <Movement>().follow = true; clickedLeft.GetComponent <Rigidbody2D>().isKinematic = false; clickedLeft.GetComponent <Movement>().follow_x = skeleton.HandLeft.x * 9f; clickedLeft.GetComponent <Movement>().follow_y = skeleton.HandLeft.y * 5f; colorLeft = clickedLeft.GetComponent <Renderer>().material.GetColor("_Color"); clickedLeft.GetComponent <Renderer>().material.SetColor("_Color", Color.gray); onlyOneLeft = false; } else if (clickedLeft != null) { clickedLeft.GetComponent <Movement>().follow = false; clickedLeft.GetComponent <Renderer>().material.SetColor("_Color", Color.white); clickedLeft.GetComponent <Movement>().first = false; clickedLeft.GetComponent <Rigidbody2D>().isKinematic = true; onlyOneLeft = true; } else { onlyOneLeft = true; } } /* * RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); * if (hit.collider != null && Input.GetMouseButtonDown(0)) * { * if (first) * { * clicked = hit.transform.gameObject; * clicked.GetComponent<Movement>().follow = true; * clicked.GetComponent<Rigidbody2D>().isKinematic = false; * first = false; * clicked.GetComponent<Movement>().first = true; * color1 = clicked.GetComponent<Renderer>().material.GetColor("_Color"); * clicked.GetComponent<Renderer>().material.SetColor("_Color", Color.gray); * } * else if(!second && hit.transform.gameObject != clicked) * { * clicked2 = hit.transform.gameObject; * clicked2.GetComponent<Movement>().follow = true; * clicked2.GetComponent<Rigidbody2D>().isKinematic = false; * second = true; * color2 = clicked2.GetComponent<Renderer>().material.GetColor("_Color"); * clicked2.GetComponent<Renderer>().material.SetColor("_Color", Color.gray); * } * } * else if(!first && second && Input.GetMouseButtonUp(0)) * { * clicked2.GetComponent<Movement>().follow = false; * clicked2.GetComponent<Renderer>().material.SetColor("_Color", color2); * clicked2.GetComponent<Rigidbody2D>().isKinematic = true; * second = false; * } */ if (destroyed == SpawnNumber) { destroyed = 0; Destroy(SpawnManager); RestartManager.gameOver(); feet = false; _background.GetComponent <SpriteRenderer>().sprite = backgrounds[5]; AudioManager.GetComponent <AudioManager>().gameWon(); } if (skeleton.isRightHandClosed(0.07f)) { rightHand.transform.GetChild(1).gameObject.SetActive(true); rightHand.transform.GetChild(0).gameObject.SetActive(false); } else { rightHand.transform.GetChild(1).gameObject.SetActive(false); rightHand.transform.GetChild(0).gameObject.SetActive(true); } if (skeleton.isLeftHandClosed(0.07f)) { leftHand.transform.GetChild(1).gameObject.SetActive(true); leftHand.transform.GetChild(0).gameObject.SetActive(false); } else { leftHand.transform.GetChild(1).gameObject.SetActive(false); leftHand.transform.GetChild(0).gameObject.SetActive(true); } }