// Update is called once per frame void Update() { if (Physics.Raycast(new Ray(transform.position, transform.forward), out RaycastHit hitInfo)) { TeleportationZone teleZone = hitInfo.collider.GetComponent <TeleportationZone>(); // Still looking at the same zone // So increase timer if (teleZone == currentTeleZone && hitInfo.distance > 2 && teleportLock == false) { // Tick the timer currentGazeTimer += Time.deltaTime; gazeBar.fillAmount = currentGazeTimer / gazeDelay; // If timer reaches end, then stop ticking and teleport user if (currentGazeTimer >= gazeDelay) { StartCoroutine(FadeTeleport(currentTeleZone.GetSnapPos())); EndGazeTimer(); } } // Make sure we are looking at a tele zone // This means we are looking at a new zone else if (teleZone != null) { // Set new looked at zone currentTeleZone = teleZone; // Move the effect teleportEffect.gameObject.SetActive(true); teleportEffect.position = teleZone.GetSnapPos(); // Start gaze timer currentGazeTimer = 0; gazeBar.fillAmount = 0; } // This means we are no longer looking at anything // But we are still increasing gaze timer so time to stop it else if (currentTeleZone != null) { EndGazeTimer(); } // Do nothing else { } } else { EndGazeTimer(); } }
// Update is called once per frame void Update() { if (Physics.Raycast(new Ray(transform.position, transform.forward), out RaycastHit hitInfo)) { lR.enabled = true; Vector3 startPoint = transform.position; TeleportationZone teleZone = hitInfo.collider.GetComponent <TeleportationZone>(); Vector3 desiredPoint; if (teleZone != null) { desiredPoint = teleZone.GetSnapPos(); } else { desiredPoint = hitInfo.point; } Vector3 vecToDesired = desiredPoint - teleportEffect.position; vecToDesired /= smoothnessValue; vecToDesired *= Time.deltaTime; Vector3 endPoint = vecToDesired + teleportEffect.position; teleportEffect.gameObject.SetActive(true); teleportEffect.position = endPoint; Vector3 midPoint = ((endPoint - startPoint) / 2f) + startPoint; midPoint.y += curverHeight; for (int i = 0; i < positionCount; i = i + 1) { Vector3 lerp1 = Vector3.Lerp(startPoint, midPoint, i / (float)positionCount); Vector3 lerp2 = Vector3.Lerp(midPoint, endPoint, i / (float)positionCount); Vector3 curvedPos = Vector3.Lerp(lerp1, lerp2, i / (float)positionCount); lR.SetPosition(i, curvedPos); } if (Input.GetButtonDown(handness.ToString() + "TriggerPress") && teleportLock == false) { StartCoroutine(FadeTeleport(endPoint)); } } else { lR.enabled = false; teleportEffect.gameObject.SetActive(false); } }
private void EndGazeTimer() { teleportEffect.gameObject.SetActive(false); // Stop ticking gaze timer currentTeleZone = null; // Stop timer teleportEffect.gameObject.SetActive(false); currentGazeTimer = -1; gazeBar.fillAmount = 0; }