void FixedUpdate() { if (active && Time.time - triggerTime <= openTime) { transform.rotation *= frameTurn; } else if (active) { active = false; if (textScroller != null) { playerControl.setCanMove(false); spawned = Instantiate(instantiate, Camera.main.transform.position + Camera.main.transform.forward * 1.5f, Camera.main.transform.rotation); spawned.transform.parent = Camera.main.transform; textScroller.ScrollText(rewardText, endText); } } }
void Update() { switch (state) { case 0: StartCoroutine(WaitPatiently()); state = 1; break; case 1: break; case 2: transform.position = Vector3.Lerp(initialPos, target.transform.position + Vector3.up * grabHeightOffset, (Time.time - triggerTime) / swingTime); transform.position += Vector3.up * heightCurve.Evaluate((Time.time - triggerTime) / swingTime); if (Time.time - triggerTime >= swingTime) { state = 3; target.setCanMove(false); audioSource.loop = false; audioSource.clip = pickupClip; audioSource.Play(); psol.PlaySound(); movingPlayer = true; } break; case 3: if (cycles == 0) { state = 7; textScroll.ScrollText(talkStrings, FinishTalking); } else { state = 4; --cycles; int index = Random.Range(0, moveStrings.Length); textScroll.ScrollText(new[] { moveStrings[index] }); } triggerTime = Time.time; grabPos = transform.position; SelectTarget(); break; case 4: transform.position = Vector3.Lerp(grabPos, targetPos, (Time.time - triggerTime) / placeTime); transform.position += Vector3.up * heightCurve.Evaluate((Time.time - triggerTime) / placeTime); if (Time.time - triggerTime >= placeTime) { state = 5; target.setCanMove(true); movingPlayer = false; } break; case 5: state = 6; triggerTime = Time.time; break; case 6: transform.position = Vector3.Lerp(targetPos, initialPos, (Time.time - triggerTime) / returnTime); transform.position += Vector3.up * heightCurve.Evaluate((Time.time - triggerTime) / returnTime); if (Time.time - triggerTime >= returnTime) { state = 0; } break; case 7: transform.position = Vector3.Lerp(grabPos, talkPos, (Time.time - triggerTime) / placeTime); transform.position += Vector3.up * heightCurve.Evaluate((Time.time - triggerTime) / placeTime); if (Time.time - triggerTime >= placeTime) { state = 8; audioSource.clip = talkClip; audioSource.loop = true; audioSource.Play(); } break; case 8: break; case 9: if (audioSource.isPlaying) { audioSource.Stop(); } transform.position = Vector3.Lerp(talkPos, endPos, (Time.time - triggerTime) / placeTime); transform.position += Vector3.up * heightCurve.Evaluate((Time.time - triggerTime) / placeTime); if (Time.time - triggerTime >= placeTime) { state = 10; triggerTime = Time.time; target.setCanMove(true); movingPlayer = false; } break; case 10: transform.position = Vector3.Lerp(endPos, initialPos, (Time.time - triggerTime) / returnTime); transform.position += Vector3.up * heightCurve.Evaluate((Time.time - triggerTime) / returnTime); if (Time.time - triggerTime >= returnTime) { state = -1; cycles = maxCycles; tg.Reset(); } break; default: break; } }