// Update is called once per frame void Update() { device = SteamVR_Controller.Input((int)controller.index); if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad)) { //load new scene //SteamVR_LoadLevel.Begin("Teleport"); //reset position of finger to 0, 0 (I think) touchLast_x = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x; touchLast_y = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).y; } //detect when our user is toucing the touchpad if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad)) { objMenu.SetActive(true); touchCurrent_x = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x; //how much did the finger move this frame? distance_x = touchCurrent_x - touchLast_x; //cache our fingers location so we know where it was last frame touchLast_x = touchCurrent_x; //add the distance travelled to the swipeSum variable swipeSum_x += distance_x; if (!hasSwipedRight) { if (swipeSum_x > 0.5f) { swipeSum_x = 0; SwipeLeft(); hasSwipedRight = true; hasSwipedLeft = false; } } if (!hasSwipedLeft) { if (swipeSum_x < -0.5f) { swipeSum_x = 0; SwipeRight(); hasSwipedLeft = true; hasSwipedRight = false; } } } if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad)) { objMenu.SetActive(false); swipeSum_x = 0; touchCurrent_x = 0; touchLast_x = 0; hasSwipedLeft = false; hasSwipedRight = false; } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { //spawn object currently selected by menu SpawnObject(); //objectMenuManager.SpawnCurrentObject(); } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) { objectMenuManager.DestroyObject(); } }
// Update is called once per frame void Update() { device = SteamVR_Controller.Input((int)trackedObj.index); if (isLeft) { if (device.GetPress(SteamVR_Controller.ButtonMask.Touchpad)) { laser.gameObject.SetActive(true); teleportAimerObject.SetActive(true); laser.SetPosition(0, gameObject.transform.position); // sets our line renderer to the position of our right controller RaycastHit hit; //to know where our teleportation ends if (Physics.Raycast(transform.position, transform.forward, out hit, 15, laserMask)) { teleportLocation = hit.point; //tells us the vector position where the collision occurs laser.SetPosition(1, teleportLocation); //aimer location teleportAimerObject.transform.position = new Vector3(teleportLocation.x, teleportLocation.y + yNudgeAmount, teleportLocation.z); } else { teleportLocation = new Vector3(transform.forward.x * 15 + transform.position.x, transform.forward.y * 15 + transform.position.y, transform.forward.z * 15 + transform.position.z); RaycastHit groundRay; if (Physics.Raycast(teleportLocation, -Vector3.up, out groundRay, 17, laserMask)) { teleportLocation = new Vector3(transform.forward.x * 15 + transform.position.x, groundRay.point.y, transform.forward.z * 15 + transform.position.z); } laser.SetPosition(1, transform.forward * 15 + transform.position); //aimer location teleportAimerObject.transform.position = teleportLocation + new Vector3(0, yNudgeAmount, 0); } } if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad)) { laser.gameObject.SetActive(false); teleportAimerObject.SetActive(false); player.transform.position = teleportLocation; } } else { if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad)) { touchLast = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad).x; } if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad)) { Swipe(); } if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad)) { Unswipe(); } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { objectMenuManager.SpawnCurrentObject(); } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) { objectMenuManager.DestroyObject(); } } }