/// <summary> /// Handles the death of a character. /// </summary> public void Die(EnumDefinitions.DeathTypes deathType) { CreateModel(deathType); //Move the death model into place and unhide newDeathModel.transform.SetPositionAndRotation(gameObject.transform.position, gameObject.transform.rotation); newDeathModel.SetActive(true); //Get all particle systems on the death model bloodEmitters = newDeathModel.GetComponentsInChildren <ParticleSystem>(); //Iterate over particle systems and play them foreach (ParticleSystem bloodEmitterSys in bloodEmitters) { //For dissolve-type deaths, set the emitter trigger (for the blood-in-water effect). if (deathType == EnumDefinitions.DeathTypes.Dissolve) { bloodEmitterSys.trigger.SetCollider(0, hazardCollider); } //Start the emitter. bloodEmitterSys.Play(); } //Destroy deathModel Destroy(newDeathModel, RespawnTime); Debug.Log("After Destroy death Model call"); }
/// <summary> /// Creates a death model to take the place of the player during the death sequence. /// </summary> /// <param name="deathType">A DeathType as declared in EnumDefinitions. Defines what model will be used for the death sequence.</param> public void CreateModel(EnumDefinitions.DeathTypes deathType) { //Set death model to correct model switch (deathType) { case EnumDefinitions.DeathTypes.Explode: newDeathModel = Instantiate(explodeModel); break; case EnumDefinitions.DeathTypes.Dissolve: newDeathModel = Instantiate(dissolveModel); break; case EnumDefinitions.DeathTypes.Burn: newDeathModel = Instantiate(dissolveModel); break; case EnumDefinitions.DeathTypes.Default: newDeathModel = Instantiate(explodeModel); break; default: newDeathModel = Instantiate(explodeModel); break; } newDeathModel.SetActive(false); }
/// <summary> /// Check for collision with hazards and update death type as necessary. /// </summary> /// <param name="collider"></param> public void HazardCheck(Collider collider) { if (collider.tag == "Hazard") { // if the hazard is active if ((collider.GetComponent <Hazard>()) != null && (collider.GetComponent <Hazard>().IsActive)) { //Change character's health by the damage of the hazard, note the minus operator to remove the health. ChangeHealth(-collider.GetComponent <Hazard>().Damage); currentDeathType = EnumDefinitions.DeathTypes.Default; if (audioManager != null) { audioManager.Play("HazardDeath"); } } } else if ((collider.GetComponent <Hazard>()) != null && (collider.tag == "DissolveHazard")) { // if the hazard is active if (collider.GetComponent <Hazard>().IsActive) { //Change character's health by the damage of the hazard, note the minus operator to remove the health. ChangeHealth(-collider.GetComponent <Hazard>().Damage); //Set death type. currentDeathType = EnumDefinitions.DeathTypes.Dissolve; //Pass the deathManager the hazard's collider for use in emitter trigger effects. deathManager.HazardCollider = collider; } } else if ((collider.GetComponent <Hazard>()) != null && (collider.tag == "BurnHazard")) { // if the hazard is active if (collider.GetComponent <Hazard>().IsActive) { //Change character's health by the damage of the hazard, note the minus operator to remove the health. ChangeHealth(-collider.GetComponent <Hazard>().Damage); //Set death type. currentDeathType = EnumDefinitions.DeathTypes.Dissolve; } } else if ((collider.GetComponent <Hazard>()) != null && (collider.tag == "ExplodeHazard")) { // if the hazard is active if (collider.GetComponent <Hazard>().IsActive) { //Change character's health by the damage of the hazard, note the minus operator to remove the health. ChangeHealth(-collider.GetComponent <Hazard>().Damage); currentDeathType = EnumDefinitions.DeathTypes.Explode; } } }
/// <summary> /// Checks for entry into triggers, including clams, checkpoints, exit doors and pistons. /// </summary> /// <param name="trigger"></param> private void OnTriggerEnter(Collider trigger) { HazardCheck(trigger); //Check for picking up clam. if (trigger.gameObject.tag == "Pickup") { FoundClam(trigger.gameObject); } //If collider is a checkpoint set new checkpoint location. else if ((trigger.gameObject.tag == "Checkpoint") && (isDead == false)) { Debug.Log("Hit checkpoint"); currentCheckpoint = trigger.gameObject; if (audioManager != null && audioPlayed == false) { //Play checkpoint activation sound audioManager.Play("Checkpoint"); audioPlayed = true; } //Get the checkpoint light script from the parent of trigger and activate light. trigger.gameObject.transform.parent.GetComponent <Checkpoint>().LightIsActivated(true); } //If the player reaches the end of the level else if ((trigger.gameObject.name == "Exit Door") && (isDead == false)) { EndLevel(); } //Check for collision with a piston. else if (trigger.gameObject.tag == "Piston") { isCollidedWithPiston = true; //If currently collided with both the piston and a surface, squishy time. if (isCollidedWithPiston == true && isCollidedWithSurface == true) { //Change character's health by the damage of the hazard, note the minus operator to remove the health. ChangeHealth(-10); currentDeathType = EnumDefinitions.DeathTypes.Explode; } } }
/// <summary> /// Allows other scripts to change the currentDeathType /// </summary> /// <param name="newDeathType">Must be an existing EnumDefinitions.DeathTypes</param> public void ChangeDeathType(EnumDefinitions.DeathTypes newDeathType) { currentDeathType = newDeathType; }