/// <summary> /// Disables the old brain, swaps it with a new one and enables it /// </summary> protected virtual void SwapBrain() { // we disable the "old" brain _character.CharacterBrain.gameObject.SetActive(false); _character.CharacterBrain.enabled = false; // we swap it with the new one _character.CharacterBrain = NewAIBrain; // we enable the new one and reset it NewAIBrain.gameObject.SetActive(true); NewAIBrain.enabled = true; NewAIBrain.ResetBrain(); }
/// <summary> /// Revives this object, turning its parts back on again /// </summary> public virtual void Revive() { if (_health != null) { _health.Revive(); } if (_aiBrain != null) { _aiBrain.ResetBrain(); } if (AutoRespawnDuration <= 0f) { // object is turned inactive to be able to reinstate it at respawn gameObject.SetActive(true); } else { foreach (MonoBehaviour component in _otherComponents) { component.enabled = true; } if (_collider2D != null) { _collider2D.enabled = true; } if (_renderer != null) { _renderer.enabled = true; } RespawnFeedback?.PlayFeedbacks(); } if (OnRevive != null) { OnRevive(); } }
// Respawn the player when it's dead at param point public void RespawnAt(Vector3 respawnPosition) { if (!_init) { Initialize(); } transform.position = respawnPosition; if (CharacterType == CharacterType.NPC) { if (_brain != null) { _brain.ResetBrain(); } } // Reset health on respawn if (_health != null) { _health.Revive(); } }
/// <summary> /// Revives this object, turning its parts back on again /// </summary> public virtual void Revive() { if (AutoRespawnDuration <= 0f) { // object is turned inactive to be able to reinstate it at respawn gameObject.SetActive(true); } else { if (DisableAllComponentsOnKill) { foreach (MonoBehaviour component in _otherComponents) { component.enabled = true; } } if (_collider2D != null) { _collider2D.enabled = true; } if (_renderer != null) { _renderer.enabled = true; } InstantiateRespawnEffect(); PlayRespawnSound(); } if (_health != null) { _health.Revive(); } if (_aiBrain != null) { _aiBrain.ResetBrain(); } OnRevive?.Invoke(); }
private void Respawn() { gameObject.SetActive(true); _health?.Revive(); _brain?.ResetBrain(); }