/// <summary> /// Revive this object. /// </summary> public virtual void Revive() { if (!_initialized) { return; } if (_collider2D != null) { _collider2D.enabled = true; } if (_collider3D != null) { _collider3D.enabled = true; } if (_characterController != null) { _characterController.enabled = true; } if (_controller != null) { _controller.enabled = true; _controller.CollisionsOn(); _controller.Reset(); } if (_character != null) { _character.ConditionState.ChangeState(CharacterStates.CharacterConditions.Normal); } if (_renderer != null) { _renderer.material.color = _initialColor; } if (RespawnAtInitialLocation) { transform.position = _initialPosition; } if (_healthBar != null) { _healthBar.Initialization(); } Initialization(); UpdateHealthBar(false); if (OnRevive != null) { OnRevive(); } }
/// <summary> /// Makes the player respawn at the location passed in parameters /// </summary> /// <param name="spawnPoint">The location of the respawn.</param> public virtual void RespawnAt(Transform spawnPoint, FacingDirections facingDirection) { transform.position = spawnPoint.position; if (!gameObject.activeInHierarchy) { gameObject.SetActive(true); //Debug.LogError("Spawn : your Character's gameobject is inactive"); } // we raise it from the dead (if it was dead) ConditionState.ChangeState(CharacterStates.CharacterConditions.Normal); // we re-enable its 2D collider if (this.gameObject.MMGetComponentNoAlloc <Collider2D>() != null) { this.gameObject.MMGetComponentNoAlloc <Collider2D>().enabled = true; } // we re-enable its 2D collider if (this.gameObject.MMGetComponentNoAlloc <Collider>() != null) { this.gameObject.MMGetComponentNoAlloc <Collider>().enabled = true; } // we make it handle collisions again _controller.enabled = true; _controller.CollisionsOn(); _controller.Reset(); // we kill all potential velocity if (this.gameObject.MMGetComponentNoAlloc <Rigidbody>() != null) { this.gameObject.MMGetComponentNoAlloc <Rigidbody>().velocity = Vector3.zero; } if (this.gameObject.MMGetComponentNoAlloc <Rigidbody2D>() != null) { this.gameObject.MMGetComponentNoAlloc <Rigidbody2D>().velocity = Vector3.zero; } Reset(); if (_health != null) { _health.ResetHealthToMaxHealth(); _health.Revive(); } if (CharacterBrain != null) { CharacterBrain.enabled = true; } // facing direction if (FindAbility <CharacterOrientation2D>() != null) { FindAbility <CharacterOrientation2D>().Face(facingDirection); } // facing direction if (FindAbility <CharacterOrientation3D>() != null) { FindAbility <CharacterOrientation3D>().Face(facingDirection); } }
/// <summary> /// Revive this object. /// </summary> public virtual void Revive() { if (!_initialized) { return; } if (_collider2D != null) { _collider2D.enabled = true; } if (_collider3D != null) { _collider3D.enabled = true; } if (DisableChildCollisionsOnDeath) { foreach (Collider2D collider in this.gameObject.GetComponentsInChildren <Collider2D>()) { collider.enabled = true; } foreach (Collider collider in this.gameObject.GetComponentsInChildren <Collider>()) { collider.enabled = true; } } if (ChangeLayerOnDeath) { gameObject.layer = _initialLayer; if (ChangeLayersRecursivelyOnDeath) { this.transform.ChangeLayersRecursively(_initialLayer); } } if (_characterController != null) { _characterController.enabled = true; } if (_controller != null) { _controller.enabled = true; _controller.CollisionsOn(); _controller.Reset(); } if (_character != null) { _character.ConditionState.ChangeState(CharacterStates.CharacterConditions.Normal); } if (_renderer != null) { _renderer.material.color = _initialColor; } if (RespawnAtInitialLocation) { transform.position = _initialPosition; } if (_healthBar != null) { _healthBar.Initialization(); } Initialization(); UpdateHealthBar(false); OnRevive?.Invoke(); }