IEnumerator Throw() { var throwDirection = GetThrowVelocity().normalized; state = newspaperThrowState.THROW; throwTarget.position = transform.position + (transform.up + throwDirection); for (float i = 0.25f; i < 0.66; i += 3 * Time.deltaTime) { handBlendAmount += 3 * Time.deltaTime; yield return(null); } if (newspapersLeft > 0) { Rigidbody rigidbody = Instantiate(newspaperPrefab, GetPaperSpawnPosition(), Quaternion.LookRotation(throwDirection)).GetComponent <Rigidbody>(); rigidbody.AddForce(GetThrowVelocity(), ForceMode.VelocityChange); newspapersLeft -= 1; newspaperInHand.SetActive(false); for (float i = 0; i < 1; i += 3 * Time.deltaTime) { handBlendAmount += 3 * Time.deltaTime; yield return(null); } } state = newspaperThrowState.NONE; }
private void Update() { switch (state) { case newspaperThrowState.NONE: handBlendAmount = Mathf.Clamp(handBlendAmount - Time.deltaTime * 3, 0, 1); throwForcePercent = 0; if (Input.GetMouseButton(1)) { state = newspaperThrowState.AIM; newspaperInHand.SetActive(true); } break; case newspaperThrowState.AIM: Vector3 throwDirection = GetThrowVelocity().normalized; throwTarget.position = transform.position + (throwDirection / 1.5f); throwTarget.rotation = Quaternion.LookRotation(Vector3.up * 0.5f, throwDirection); handBlendAmount = -0.001f; handThrowRig.weight = 0.66f; throwForcePercent = Mathf.Clamp01(throwForcePercent + Time.deltaTime); if (Input.GetMouseButtonUp(1)) { state = newspaperThrowState.NONE; newspaperInHand.SetActive(false); } else if (Input.GetMouseButtonDown(0)) { StartCoroutine(Throw()); } break; } if (handBlendAmount >= 0) { handThrowRig.weight = handBlendAmount; } UpdateThrowVisuals(); }