IEnumerator DeathAndRespawn() { GetComponent <Collider2D>().enabled = false; CameraFollow.instance.FocusOn(transform.position, blackenTime + 6f); effectsStorage.PlayEffect(1); //Death SFX foreach (GameObject enemy in GameObject.FindGameObjectsWithTag("Enemy")) { if (enemy.transform.root != transform.root && enemy.GetComponent <Damageable>() != null) { enemy.GetComponent <Damageable>().Die(); } } GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, 0); GetComponent <Collider2D>().enabled = false; // hitbox ai.StopAI(); StartCoroutine(Blacken(blackenTime)); yield return(new WaitForSeconds(blackenTime)); Utils.SpawnScaledParticleSystem(ParticleType.Ashes, transform.parent); // BurnToAshes yield return(new WaitForSeconds(0.5f)); yield return(new WaitForSeconds(1f)); // for particles to naturally disappear effectsStorage.PlayEffect(2); // Respawn SFX GetComponentInParent <Animation>().Play("SnakeRespawn"); yield return(new WaitForSeconds(4f)); // Respawn length sr.color = new Color(1, 1, 1, 1); bodySr.color = new Color(1, 1, 1, 1); GetComponentInParent <Animation>().Play("CheckpointFloat"); RestoreHealth(maxHealth - currHealth); GetComponent <Collider2D>().enabled = true; // hitbox CameraFollow.instance.FocusOn(transform.position + Vector3.up * 20, 3); yield return(new WaitForSeconds(1.5f)); if (!hasDied) { Instantiate(doubleJumpPowerup, transform.position, Quaternion.identity); hasDied = true; } yield return(new WaitForSeconds(1.5f)); GetComponent <Collider2D>().enabled = true; ai.StartAI(); }
private void ShootProjectile() { effectsStorage.PlayEffect(0); // Shoot SFX Vector2 aimDirection = target.position - headTransform.position; GameObject projectileInst = Instantiate(projectilePrefab, (Vector2)headTransform.position + aimDirection.normalized * 1.5f, Quaternion.FromToRotation(Vector3.up, aimDirection)); shootAmount--; }
void Start() { rb = GetComponent <Rigidbody2D>(); sprite = transform.GetChild(0); sr = sprite.GetComponent <SpriteRenderer>(); particle = GetComponentInChildren <ParticleSystem>().main; damageable = GetComponent <Damageable>(); burningFilter = new ContactFilter2D(); burningFilter.useTriggers = true; burningFilter.SetLayerMask(LayerMask.GetMask("Burning")); // DO NOT use LayerMask.NameToLayer here -- it returns an int instead of bitmask // print("burning filter: " + LayerMask.LayerToName(burningFilter.layerMask)); fireHitbox = transform.GetChild(1).gameObject; animator = sprite.GetComponent <Animator>(); effectsStorage = GetComponent <EffectsStorage>(); effectsStorage.PlayEffect(2); // spawn SFX if (PersistentManager.instance == null) { Instantiate(Utils.persistentManager, Vector3.zero, Quaternion.identity); } volumeProfile.TryGet(out bloom); bloom.intensity.value = 0.5f; }
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(); } } }