// HELPERS private void CheckForInteractionObject() { Collider[] overlappedColliders = Physics.OverlapSphere(snapColliderOrigin.position, snapColliderOrigin.lossyScale.x / 2f); foreach (Collider overlappedCollider in overlappedColliders) { if (overlappedCollider.CompareTag("InteractionObject") && overlappedCollider.GetComponentInParent <WI_InteractionObject> ().IsFree()) { objectBeingInteractedWith = overlappedCollider.GetComponentInParent <WI_InteractionObject> (); objectBeingInteractedWith.OnTriggerWasPressed(this); Debug.Log("object: " + objectBeingInteractedWith.name); return; } } }
// Runs once per frame and checks for interactions // Certain interactions indicate object interactions // Certain others don't, like teleportation. void Update() { // Checks for Trigger Interactions if (Controller.GetHairTriggerDown()) { CheckForInteractionObject(); } if (Controller.GetHairTrigger()) { if (objectBeingInteractedWith) { objectBeingInteractedWith.OnTriggerIsBeingPressed(this); } } if (Controller.GetHairTriggerUp()) { if (objectBeingInteractedWith) { objectBeingInteractedWith.OnTriggerWasReleased(this); objectBeingInteractedWith = null; } } // Checks for Button Interactions if (PressDown()) { if (objectBeingInteractedWith) { objectBeingInteractedWith.OnPressDown(this); } } if (PressUp()) { if (objectBeingInteractedWith) { objectBeingInteractedWith.OnPressUp(this); } } // Teleportation if (PressLeft()) { Debug.Log("Button Pressed."); RaycastHit hit; if (Physics.Raycast(trackedObj.transform.position, transform.forward, out hit, 100, teleportMask)) { hitPoint = hit.point; // Laser teleportLaser.SetActive(true); teleportLaser.transform.localPosition = new Vector3(0.0f, 0.0f, hit.distance * 0.5f); //laser.transform.position = Vector3.Lerp(trackedObj.transform.position, hitPoint, .5f); //laser.transform.LookAt(hitPoint); // Rotate laser facing the hit point teleportLaser.transform.localScale = new Vector3(teleportLaser.transform.localScale.x, teleportLaser.transform.localScale.y, hit.distance); teleportHitIndicator.SetActive(true); teleportHitIndicator.transform.position = hitPoint; shouldTeleport = true; Debug.Log("Should teleport now..."); } else { teleportLaser.SetActive(false); teleportHitIndicator.SetActive(false); } } if (Controller.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad) && shouldTeleport) { Debug.Log("Teleport in progress."); Teleport(); } if (PressRight()) { if (this.GetComponent <FixedJoint> ()) { SetHandMenuActive(true); } } }
public void SwitchInteractionObjectTo(WI_InteractionObject interactionObject) { objectBeingInteractedWith = interactionObject; objectBeingInteractedWith.OnTriggerWasPressed(this); }