Exemple #1
0
        /// <summary>
        /// Spawns an object out of the pool if there's one available.
        /// If it's an object with Health, revives it too.
        /// </summary>
        protected virtual void Spawn()
        {
            GameObject nextGameObject = ObjectPooler.GetPooledGameObject();

            // mandatory checks
            if (nextGameObject == null)
            {
                return;
            }
            if (nextGameObject.GetComponent <MMPoolableObject>() == null)
            {
                throw new Exception(gameObject.name + " is trying to spawn objects that don't have a PoolableObject component.");
            }
            // we position the object
            nextGameObject.transform.position = this.transform.position;

            // we activate the object
            nextGameObject.gameObject.SetActive(true);
            nextGameObject.gameObject.MMGetComponentNoAlloc <MMPoolableObject>().TriggerOnSpawnComplete();

            // we check if our object has an Health component, and if yes, we revive our character
            Health objectHealth = nextGameObject.gameObject.MMGetComponentNoAlloc <Health> ();

            if (objectHealth != null)
            {
                objectHealth.Revive();
            }

            // we reset our timer and determine the next frequency
            _lastSpawnTimestamp = Time.time;
            DetermineNextFrequency();
        }
        /// <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();
            }
        }
Exemple #3
0
        /// <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)
        {
            if (!gameObject.activeInHierarchy)
            {
                //Debug.LogError("Spawn : your Character's gameobject is inactive");
                return;
            }

            // we make sure the character is facing right
            Face(facingDirection);

            // we raise it from the dead (if it was dead)
            ConditionState.ChangeState(CharacterStates.CharacterConditions.Normal);
            // we re-enable its 2D collider
            GetComponent <Collider2D>().enabled = true;
            // we make it handle collisions again
            _controller.CollisionsOn();
            transform.position = spawnPoint.position;
            if (_health != null)
            {
                _health.ResetHealthToMaxHealth();
                _health.Revive();
            }
        }