IEnumerator LookAtTarget(Vector3 target, float duration) { rotating = true; float elapsedTime = 0f; float ratio = 0f; Vector3 begin = transform.position + transform.forward; bool playerMoved = PlayerHasMoved(); while (elapsedTime < duration) { ratio = elapsedTime / duration; elapsedTime += Time.deltaTime; Vector3 view = Vector3.Lerp(begin, target, ratio); FrogLook(view); if (audio && playerMoved && Toolbox.Instance.PlayerInLaser()) { audio.volume = Toolbox.Instance.soundEffectsVolume * TweeningFunctions.BackAndForth(ratio); } yield return(null); } audio.volume = 0f; rotating = false; previousPlayerPosition = player.position; }
private IEnumerator flipTransitionRoutine(float startpoint, float endpoint, float duration, bool goingToLaser) { partner.GetComponent <Transition>().enabled = false; Debug.Log("duration " + duration); isRunning = true; //.isRunning = true; float elapsedTime = 0; float ratio = elapsedTime / duration; int count = 0; while (ratio < 1f) { ratio = elapsedTime / duration; float value = Mathf.Lerp(startpoint, endpoint, TweeningFunctions.BackAndForth(ratio)); float transitionBValue; if (!goingToLaser) { transitionBValue = Mathf.Lerp(1f, 0f, ratio); } else { transitionBValue = Mathf.Lerp(0f, 1f, ratio); } partnerRenderer.GetPropertyBlock(_propBlock); _propBlock.SetFloat("_TransitionState", value); partnerRenderer.SetPropertyBlock(_propBlock); partnerMaterial.SetFloat("_TransitionStateB", transitionBValue); if (Toolbox.Instance.GetFlip().flippedThisFrame) { count += 1; if (count > 1) { recentlySelected = false; isRunning = false; SetMaterialFloatProp("_onHold", 0f); SetMaterialFloatProp("_Shimmer", 0f); yield break; } } elapsedTime += Time.deltaTime; yield return(null); } //recentlySelected = false; isRunning = false; // partnerLinkedPair.isRunning = false; cancelTransition = 0; partner.GetComponent <Transition>().enabled = true; }
IEnumerator RotateRoutine(float actualDuration) { //Debug.Log("start rotation "+ startRotation + "end rotation " + endRotation + "actualduration " + actualDuration); float elapsedTime = 0f; ratio = 0f; Vector3 start = transform.localEulerAngles; Vector3 end; if (startRotationInLaser && Toolbox.Instance.PlayerInLaser() || (!startRotationInLaser && Toolbox.Instance.PlayerInReal())) { end = startRotation; } else { end = endRotation; } while (ratio < 1f) { ratio = elapsedTime / actualDuration; Vector3 value = Vector3.Lerp(start, end, TweeningFunctions.Tween(tween, ratio)); transform.localEulerAngles = value; if (audio) { audio.volume = TweeningFunctions.BackAndForth(ratio); } elapsedTime += Time.fixedDeltaTime; yield return(new WaitForFixedUpdate()); } ratio = 0f; }