private void OnTriggerExit(Collider other) { if (switchPos == SWITCH_POSITION_E.DISABLED) { return; } if (other.name == "HandTrackedBlock") { // Debug.Log("PistonvicinityManager OnTriggerExit"); // Leaving the vicinity, go back to ready state switchPos = SWITCH_POSITION_E.READY; _tempObject = null; hoverState.SetActive(false); CE._emitter.stop(); if (PushedDown == true) { TiralComplete = true; CE._emitter.stop(); } } }
void Update() { // if the hand is in the vicinity of the collider/buttopTop // set the button top position to the colliding object else reset the position back to default if (_tempObject != null) { _buttonPositionY = _tempObject.transform.position.y - _offset; setPressPosition(_buttonPositionY); if (switchPos == SWITCH_POSITION_E.READY) { Debug.Log("_buttonPositionY" + _buttonPositionY); Debug.Log("_buttonMaxYValue" + _buttonMaxYValue); if (_buttonPositionY > _buttonMaxYValue) { hoverState.SetActive(true); CE._emitter.start(); switchPos = SWITCH_POSITION_E.ACTUATING; } } else if (switchPos == SWITCH_POSITION_E.ACTUATING) { // Update pressing haptic setPressHapticIntensity((_pistonPresser.transform.position.y - _buttonMinYValue) / _pistonTravelDistance); if (_buttonPositionY < _buttonMinYValue) { switchPos = SWITCH_POSITION_E.CLICKED; pressComplete(); } } else if (switchPos == SWITCH_POSITION_E.CLICKED) { if (_buttonPositionY >= _buttonClickUpPosition) { // Hand is moving back up out off the button. switchPos = SWITCH_POSITION_E.ACTUATING; clickComplete(); } } } else { // Catch button state if leaving vicinity if (_buttonPositionY < _buttonMaxYValue) { // Return the button position back to initial value. float damping = 0.1f; _buttonPositionY = _buttonPositionY + damping * (_buttonMaxYValue - _buttonPositionY); _buttonPositionY = Mathf.Min(_buttonPositionY, _buttonMaxYValue); _pistonPresser.transform.position = new UnityEngine.Vector3(_pistonPresser.transform.position.x, _buttonPositionY, _pistonPresser.transform.position.z); } } }
void Update() { if (Block.transform.position == end) { reachedEnd = true; } //FIRST STAGE // if the hand is in the vicinity of the collider/buttopTop // set the button top position to the colliding object else reset the position back to default if (reachedEnd == false) { if (_tempObject != null) { _buttonPositionY = _tempObject.transform.position.z - _offset; setPressPosition(_buttonPositionY); if (switchPos == SWITCH_POSITION_E.READY) { if (_buttonPositionY > _buttonMaxYValue) { CE._emitter.start(); switchPos = SWITCH_POSITION_E.ACTUATING; } } else if (switchPos == SWITCH_POSITION_E.ACTUATING) { // Update pressing haptic setPressHapticIntensity((_pistonPresser.transform.position.z - _buttonMinYValue) / _pistonTravelDistance); if (_buttonPositionY < _buttonMinYValue) { switchPos = SWITCH_POSITION_E.CLICKED; pressComplete(); } } else if (switchPos == SWITCH_POSITION_E.CLICKED) { if (_buttonPositionY >= _buttonClickUpPosition) { // Hand is moving back up out off the button. switchPos = SWITCH_POSITION_E.ACTUATING; clickComplete(); } } } else { // Catch button state if leaving vicinity if (_buttonPositionY < _buttonMaxYValue) { // Return the button position back to initial value. float damping = 0.1f; _buttonPositionY = _buttonPositionY + damping * (_buttonMaxYValue - _buttonPositionY); _buttonPositionY = Mathf.Min(_buttonPositionY, _buttonMaxYValue); _pistonPresser.transform.position = new UnityEngine.Vector3(_pistonPresser.transform.position.x, _pistonPresser.transform.position.y, _buttonPositionY); } } } //SECOND STAGE if (reachedEnd == true) { _maxPressIntensity = 1.0f; // if the hand is in the vicinity of the collider/buttopTop // set the button top position to the colliding object else reset the position back to default if (_tempObject != null) { _buttonPositionY = _tempObject.transform.position.z - _offset; setPressPosition(_buttonPositionY); if (switchPos == SWITCH_POSITION_E.READY) { if (_buttonPositionY > _buttonMaxYValue) { switchPos = SWITCH_POSITION_E.ACTUATING; } } else if (switchPos == SWITCH_POSITION_E.ACTUATING) { // Update pressing haptic setPressHapticIntensity((_pistonPresser.transform.position.z - _buttonMinYValue) / _pistonTravelDistance); if (_buttonPositionY < _buttonMinYValue) { switchPos = SWITCH_POSITION_E.CLICKED; pressComplete(); } } else if (switchPos == SWITCH_POSITION_E.CLICKED) { if (_buttonPositionY >= _buttonClickUpPosition) { // Hand is moving back up out off the button. switchPos = SWITCH_POSITION_E.ACTUATING; clickComplete(); } } } else { // Catch button state if leaving vicinity if (_buttonPositionY < _buttonMaxYValue) { // Return the button position back to initial value. float damping = 0.1f; _buttonPositionY = _buttonPositionY + damping * (_buttonMaxYValue - _buttonPositionY); _buttonPositionY = Mathf.Min(_buttonPositionY, _buttonMaxYValue); _pistonPresser.transform.position = new UnityEngine.Vector3(_pistonPresser.transform.position.x, _pistonPresser.transform.position.z, _buttonPositionY); } } } }