void Update() { if (controller == null) // Debug message for if controller doesn't exist { Debug.Log("Controller not initialized"); return; } // If touch pad is touched, move player in appropriate direction if (controller.GetTouch(touchPad)) { Vector2 dir = controller.GetAxis(); // Get touch coordinates float rotation = -head.GetComponent <Transform> ().rotation.eulerAngles.y; // Rotate touch coordinates by player's y-axis rotation to ensure movement is relative to this rotation float sin = Mathf.Sin(rotation * Mathf.Deg2Rad); float cos = Mathf.Cos(rotation * Mathf.Deg2Rad); float tx = dir.x; float ty = dir.y; dir.x = (cos * tx) - (sin * ty); dir.y = (sin * tx) + (cos * ty); if (dir.x < -0.2) { if (dir.y < -0.2) { cam.Move("Backward and Left"); } else if (dir.y > 0.2) { cam.Move("Forward and Left"); } else { cam.Move("Left"); } } else if (dir.x > 0.2) { if (dir.y < -0.2) { cam.Move("Backward and Right"); } else if (dir.y > 0.2) { cam.Move("Forward and Right"); } else { cam.Move("Right"); } } else { if (dir.y < -0.2) { cam.Move("Backward"); } else if (dir.y > 0.2) { cam.Move("Forward"); } } } // If trigger button is pressed, pick up object if (controller.GetPressDown(triggerButton)) { float minDistance = float.MaxValue; float distance; // Find the nearest object the hands are currently overlapping foreach (InteractableObject item in objectsHoveringOver) { distance = (item.transform.position - transform.position).sqrMagnitude; if (distance < minDistance) { minDistance = distance; closestObject = item; } } interactingObject = closestObject; // Set this nearest object as the one being picked up by the hands closestObject = null; // Null out reference to closest object if (interactingObject) { // If nearest object is already held by opposite hand when trigger button is pressed, drop it from that hand before attaching it to this hand if (interactingObject.IsInteracting()) { interactingObject.EndInteraction(this); } interactingObject.BeginInteraction(this); } // If the trigger button is pressed while the Restart button is enabled, reset the scene if (restart.enabled == true) { restart.Press(); } } // If trigger button is unpressed while hand is holding an object, drop object if (controller.GetPressUp(triggerButton) && interactingObject != null) { interactingObject.EndInteraction(this); } // If grip button is pressed while player is not crouched, move player to crouching position if (controller.GetPressDown(gripButton) && (Data.crouched == Data.UNCROUCHED)) { Vector3 temp = player.GetComponent <Transform>().position; temp.y = (temp.y - 50) * Time.deltaTime; player.GetComponent <Transform>().position = temp; Data.crouched = Data.CROUCHED; } // If grip button is released while player is crouched, move player out of crouching position if (controller.GetPressUp(gripButton) && (Data.crouched == Data.CROUCHED)) { Vector3 temp = player.GetComponent <Transform>().position; temp.y = (temp.y + 50) * Time.deltaTime; player.GetComponent <Transform>().position = temp; Data.crouched = Data.UNCROUCHED; } }
void Update() { if (controller == null) { Debug.Log("Controller not initialized"); return; } if (Jump) { if (controller.GetPressUp(touchPad)) { /* * Vector2 dir = controller.GetAxis(); * float rotation = -head.GetComponent<Transform>().rotation.eulerAngles.y; * float sin = Mathf.Sin(rotation * Mathf.Deg2Rad); * float cos = Mathf.Cos(rotation * Mathf.Deg2Rad); * float tx = dir.x; * float ty = dir.y; * * dir.x = (cos * tx) - (sin * ty); * dir.y = (sin * tx) + (cos * ty); * * if (dir.x < -0.2) * { * if (dir.y < -0.2) * cam2.Move("Backward and Left"); * else if (dir.y > 0.2) * cam2.Move("Forward and Left"); * else * cam2.Move("Left"); * * } * else if (dir.x > 0.2) * { * if (dir.y < -0.2) * cam2.Move("Backward and Right"); * else if (dir.y > 0.2) * cam2.Move("Forward and Right"); * else * cam2.Move("Right"); * * } * else * { * if (dir.y < -0.2) * cam2.Move("Backward"); * else if (dir.y > 0.2) * cam2.Move("Forward"); * * } */ } } else { if (controller.GetTouch(touchPad)) { /* * Vector2 dir = controller.GetAxis(); * float rotation = -head.GetComponent<Transform>().rotation.eulerAngles.y; * float sin = Mathf.Sin(rotation * Mathf.Deg2Rad); * float cos = Mathf.Cos(rotation * Mathf.Deg2Rad); * float tx = dir.x; * float ty = dir.y; * * dir.x = (cos * tx) - (sin * ty); * dir.y = (sin * tx) + (cos * ty); * * if (dir.x < -0.2) * { * if (dir.y < -0.2) * cam.Move("Backward and Left"); * else if (dir.y > 0.2) * cam.Move("Forward and Left"); * else * cam.Move("Left"); * * } * else if (dir.x > 0.2) * { * if (dir.y < -0.2) * cam.Move("Backward and Right"); * else if (dir.y > 0.2) * cam.Move("Forward and Right"); * else * cam.Move("Right"); * * } * else * { * if (dir.y < -0.2) * cam.Move("Backward"); * else if (dir.y > 0.2) * cam.Move("Forward"); * * } */ } } if (controller.GetPressDown(triggerButton)) { Debug.Log("trigger"); /* * if (pickUp) * { * interacting.SetActive(false); * PlayerController.count++; * } */ float minDistance = float.MaxValue; float distance; foreach (InteractableObject item in objectsHoveringOver) { distance = (item.transform.position - transform.position).sqrMagnitude; if (distance < minDistance) { minDistance = distance; closestObject = item; } } interactingObject = closestObject; closestObject = null; if (interactingObject) { if (interactingObject.IsInteracting()) { Debug.Log("Special Dropped"); interactingObject.EndInteraction(this); } Debug.Log("Grabbed"); interactingObject.BeginInteraction(this); } } if (controller.GetPressUp(triggerButton) && interactingObject != null) { Debug.Log("Dropped"); interactingObject.EndInteraction(this); } if (controller.GetPressDown(gripButton) && (Data.crouched == Data.UNCROUCHED)) { //player.GetComponent<Transform>().Translate(new Vector3(0, -100, 0) * Time.deltaTime); Vector3 temp = player.GetComponent <Transform>().position; temp.y = (temp.y - 50) * Time.deltaTime; player.GetComponent <Transform>().position = temp; Data.crouched = Data.CROUCHED; } if (controller.GetPressUp(gripButton) && (Data.crouched == Data.CROUCHED)) { //player.GetComponent<Transform>().Translate(new Vector3(0, 100, 0) * Time.deltaTime); Vector3 temp = player.GetComponent <Transform>().position; temp.y = (temp.y + 50) * Time.deltaTime; player.GetComponent <Transform>().position = temp; Data.crouched = Data.UNCROUCHED; } }