IEnumerator WaitForRespawn(float wait) { yield return(new WaitForSeconds(wait * 0.2f)); if (PersistentManager.instance != null) { PersistentManager.Reload(); } }
void Update() { UpdateSpriteJumpColor(); if (Input.GetKeyDown(KeyCode.R)) { PersistentManager.Reload(); } if (Input.GetKeyDown(KeyCode.PageUp)) { int sceneID = SceneManager.GetActiveScene().buildIndex; SceneManager.LoadScene(sceneID + 1); } else if (Input.GetKeyDown(KeyCode.PageDown)) { int sceneID = SceneManager.GetActiveScene().buildIndex; SceneManager.LoadScene(sceneID - 1); } Vector3 mousePosition = Utils.MouseWorldPosition(); Vector3 aimVector = mousePosition - transform.position; Vector3 aimDirection = aimVector.normalized; handleTimers(); if (canSwim && inSwimMode) // constantly move towards cursor { float mag = aimVector.magnitude; float amount = Mathf.Min(mag > 3f ? Mathf.Log(mag) : 0f, 2f); // scale with distance from player to cursor logarithmically, cap at 2 print("Amount: " + amount + " Mouse dist: " + mag); rb.AddForce(aimDirection * amount * 0.15f, ForceMode2D.Impulse); // TODO - should we set AirJumpBehaviour to PreserveMomentum only when swimming? or all the time? } // stop all input if hovering over UI element if (EventSystem.current.IsPointerOverGameObject()) { return; } if (!isCharging) { if (!inSwimMode && Input.GetMouseButtonDown(1)) // right click { if (damageable.currHealth > 1) // prevent death from clicking { LaunchProjectile(aimDirection); } } else if (Input.GetMouseButton(0) && chargeCooldownTimer == 0f) { if (maxJumps == -1 || jumpTimes < maxJumps) { isCharging = true; chargeStartTime = Time.time; sprite.localScale = new Vector3(1, 0.5f, 1); Time.timeScale = aimingTimeScale; if (playChargingSound) { playChargingSound = false; effectsStorage.PlayEffect(3); // charge SFX } if (airJumpBehaviour == AirJumpBehaviour.CancelOnAim) { rb.velocity = new Vector3(0.0f, 0.0f, 0.0f); rb.gravityScale = 0; } // Instantiate LaunchBar activeLaunchBar = Instantiate(launchBar, transform.position, Quaternion.FromToRotation(Vector3.right, aimDirection), transform).GetComponent <LaunchBar>(); } else { // possibly play an "invalid" sound } } } else // already charging { /*if (Input.GetMouseButton(0) && Time.time - chargeStartTime > maxJumpCharge && isCharging) // Jump when held too long * { * FinishCharge(Time.time - chargeStartTime, aimDirection); * } * else*/ if (Input.GetMouseButton(0)) { // When holding down button, increase bar if (activeLaunchBar != null) { float percent = Mathf.Min((Time.time - chargeStartTime) / maxChargeTime, 1f); activeLaunchBar.SetSize(percent); activeLaunchBar.UpdateDirection(Quaternion.FromToRotation(Vector3.right, aimDirection)); } } else if (Input.GetMouseButtonUp(0)) // Jump when release { FinishCharge(Time.time - chargeStartTime, aimDirection); } if (Input.GetMouseButtonDown(1)) // cancel charge { FinishCharge(); } } }