// Update is called once per frame void Update() { OVRInput.Update(); // // Update buttons pressed // Dictionary <InputState.InputIntent, bool> Buttons = new Dictionary <InputState.InputIntent, bool>(); if (DominantHand == OVRInput.Controller.LTouch) { Buttons[InputState.InputIntent.Selection] = OVRInput.Get(OVRInput.Button.One, OVRInput.Controller.LTouch) || OVRInput.Get(OVRInput.RawButton.LIndexTrigger, OVRInput.Controller.LTouch); Buttons[InputState.InputIntent.MissileTrigger] = OVRInput.Get(OVRInput.RawButton.RIndexTrigger, OVRInput.Controller.RTouch); } else { Buttons[InputState.InputIntent.Selection] = OVRInput.Get(OVRInput.Button.One, OVRInput.Controller.RTouch) || OVRInput.Get(OVRInput.RawButton.RIndexTrigger, OVRInput.Controller.RTouch); Buttons[InputState.InputIntent.MissileTrigger] = OVRInput.Get(OVRInput.RawButton.LIndexTrigger, OVRInput.Controller.LTouch); } // // Update input direction // Vector3 cameraPos = OVRCamera.transform.position; if (DominantHand == OVRInput.Controller.RTouch) { DominantHandRay.origin = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch) + cameraPos; DominantHandRay.direction = OVRCamera.rightControllerAnchor.forward; SecondaryHandRay.origin = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch) + cameraPos; SecondaryHandRay.direction = OVRCamera.leftControllerAnchor.forward; } else { SecondaryHandRay.origin = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch) + cameraPos; SecondaryHandRay.direction = OVRCamera.rightControllerAnchor.forward; DominantHandRay.origin = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch) + cameraPos; DominantHandRay.direction = OVRCamera.leftControllerAnchor.forward; } InputDemuxer.SetInputState(Buttons, DominantHandRay, SecondaryHandRay); }
// Update is called once per frame void Update() { Dictionary <InputState.InputIntent, bool> Buttons = new Dictionary <InputState.InputIntent, bool>(); //Detect when there is a mouse click if (Input.mousePresent) { //Create a ray from the Mouse click position Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //Initialise the enter variable float enter = 0.0f; if (MousePlane.Raycast(ray, out enter)) { //Get the point that is clicked VirtualHandPosition = ray.GetPoint(enter); //Move your cube GameObject to the point where you clicked VirtualHand.transform.position = VirtualHandPosition; } float xRelativePosFromCenter = (Input.mousePosition.x - (Screen.width / 2)) / Screen.width; float zPos = Input.mousePosition.y / Screen.height; float zRelativePosFromCenter = zPos - 0.5F; if (InputMode == PlayerTargetManager.InputTarget.TowerDefenseScene) { // Black magic that needs to change if we ever change the camera position! Vector3 SelectionRayTarget = new Vector3((70.0F * xRelativePosFromCenter) - 2.0F, 0.0F, (100.0F * zRelativePosFromCenter) + 15.0F); VirtualHandDirection = (SelectionRayTarget - VirtualHandPosition).normalized; } else if (InputMode == PlayerTargetManager.InputTarget.MenuScene) { VirtualHandDirection = new Vector3(10.0F * xRelativePosFromCenter, 10.0F * zRelativePosFromCenter, 20.0F); VirtualHandDirection = VirtualHandDirection.normalized; } Buttons[InputState.InputIntent.Selection] = Input.GetMouseButtonDown(0); Buttons[InputState.InputIntent.MissileTrigger] = Input.GetKeyDown(KeyCode.X); if (Input.GetMouseButton(1)) { Vector2 currentPos = new Vector2(Input.mousePosition.x, Input.mousePosition.y); if (wasMiddleClickEnabled) { MiddleClickMouseMovement = currentPos - PreviousMiddleClickMousePos; } PreviousMiddleClickMousePos = currentPos; wasMiddleClickEnabled = true; } else { MiddleClickMouseMovement = Vector2.zero; wasMiddleClickEnabled = false; } InputDemuxer.SetInputState(Buttons, new Ray(VirtualHandPosition, VirtualHandDirection), new Ray(VirtualHandPosition, VirtualHandDirection)); } }