Example #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 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 position the object
            nextGameObject.transform.position = this.transform.position;

            // we reset our timer and determine the next frequency
            _lastSpawnTimestamp = Time.time;
            DetermineNextFrequency();
        }
Example #2
0
        /// <summary>
        /// When the player respawns, we reinstate this agent.
        /// </summary>
        /// <param name="checkpoint">Checkpoint.</param>
        /// <param name="player">Player.</param>
        public virtual void OnPlayerRespawn(CheckPoint checkpoint, Character player)
        {
            if (RepositionToInitOnPlayerRespawn)
            {
                this.transform.position = _initialPosition;
            }

            if (RespawnOnPlayerRespawn)
            {
                if (_health != null)
                {
                    _health.Revive();
                }
                Revive();
            }
            AutoRespawnRemainingAmount = AutoRespawnAmount;
        }
Example #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)
            {
                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 (_aiBrain != null)
            {
                _aiBrain.enabled = true;
            }

            // facing direction
            if (this.gameObject.MMGetComponentNoAlloc <CharacterOrientation2D>() != null)
            {
                this.gameObject.MMGetComponentNoAlloc <CharacterOrientation2D>().Face(facingDirection);
            }
            // facing direction
            if (this.gameObject.MMGetComponentNoAlloc <CharacterOrientation3D>() != null)
            {
                this.gameObject.MMGetComponentNoAlloc <CharacterOrientation3D>().Face(facingDirection);
            }

            transform.position = spawnPoint.position;
        }