Exemple #1
0
        /// <summary>
        /// Triggered when the shark collides with the player
        /// </summary>
        /// <param name="collidingObject">the object that collides with our shark.</param>
        protected virtual void OnTriggerEnter2D(Collider2D collidingObject)
        {
            // we verify that the colliding object is a PlayableCharacter with the Player tag. If not, we do nothing.
            PlayableCharacter player = collidingObject.GetComponent <PlayableCharacter>();

            if (player == null)
            {
                return;
            }
            if (collidingObject.tag != "Player")
            {
                return;
            }

            // we shake the camera - uncomment these two lines if you want to add a shake effect when the shark collides with your player. I thought it was a bit too much.
            //Vector3 ShakeParameters = new Vector3(1.5f, 0.5f, 1f);
            //_camera.Shake(ShakeParameters);

            // we instantiate an explosion at the point of impact.
            GameObject explosion = (GameObject)Instantiate(Explosion);

            explosion.transform.position = new Vector3(transform.GetComponent <Renderer>().bounds.min.x, transform.GetComponent <Renderer>().bounds.center.y, 0);
            MMAnimator.UpdateAnimatorBoolIfExists(explosion.GetComponent <Animator>(), "Explode", true);
            // we turn the object inactive so it can be instantiated again
            gameObject.SetActive(false);
        }
Exemple #2
0
        /// <summary>
        /// Coroutine that kills the player, stops the camera, resets the points.
        /// </summary>
        /// <returns>The player co.</returns>
        protected virtual IEnumerator KillCharacterCo(PlayableCharacter player)
        {
            GameManager.Instance.CurrentPlayableCharacters.Remove(player);
            player.Die();
            yield return(new WaitForSeconds(0.5f));

            // if this was the last character, we trigger the all characters are dead coroutine
            if (GameManager.Instance.CurrentPlayableCharacters.Count == 0)
            {
                AllCharactersAreDead();
            }
        }
Exemple #3
0
 /// <summary>
 /// Instantiates all the playable characters and feeds them to the gameManager
 /// </summary>
 protected virtual void InstantiateCharacters()
 {
     /// we go through the list of playable characters and instantiate them while adding them to the game manager
     GameManager.Instance.CurrentPlayableCharacters = new List <PlayableCharacter>();
     // for each character in the PlayableCharacters list
     for (int i = 0; i < PlayableCharacters.Count; i++)
     {
         // we instantiate the corresponding prefab
         PlayableCharacter instance = (PlayableCharacter)Instantiate(PlayableCharacters[i]);
         // we position it based on the StartingPosition point
         instance.transform.position = new Vector2(StartingPosition.transform.position.x + i * DistanceBetweenCharacters, StartingPosition.transform.position.y);
         // we set manually its initial position
         instance.SetInitialPosition(instance.transform.position);
         // we feed it to the game manager
         GameManager.Instance.CurrentPlayableCharacters.Add(instance);
     }
 }
Exemple #4
0
        /// <summary>
        /// Triggered when we collide with either a 2D or 3D collider
        /// </summary>
        /// <param name="collidingObject">Colliding object.</param>
        protected virtual void TriggerEnter(GameObject collidingObject)
        {
            // we verify that the colliding object is a PlayableCharacter with the Player tag. If not, we do nothing.
            if (collidingObject.tag != "Player")
            {
                return;
            }

            PlayableCharacter player = collidingObject.GetComponent <PlayableCharacter>();

            if (player == null)
            {
                return;
            }

            // we ask the LevelManager to kill the character
            LevelManager.Instance.KillCharacter(player);
        }
Exemple #5
0
        /// <summary>
        /// Instantiates all the playable characters and feeds them to the gameManager
        /// </summary>
        protected virtual void InstantiateCharacters()
        {
            CurrentPlayableCharacters = new List <PlayableCharacter>();
            /// we go through the list of playable characters and instantiate them while adding them to the list we'll use from any class to access the
            /// currently playable characters

            // we check if there's a stored character in the game manager we should instantiate
            if (CharacterSelectorManager.Instance.StoredCharacter != null)
            {
                PlayableCharacter newPlayer = (PlayableCharacter)Instantiate(CharacterSelectorManager.Instance.StoredCharacter, StartingPosition.transform.position, StartingPosition.transform.rotation);
                newPlayer.name = CharacterSelectorManager.Instance.StoredCharacter.name;
                newPlayer.SetInitialPosition(newPlayer.transform.position);
                CurrentPlayableCharacters.Add(newPlayer);
                MMEventManager.TriggerEvent(new MMGameEvent("PlayableCharactersInstantiated"));
                return;
            }

            if (PlayableCharacters == null)
            {
                return;
            }

            if (PlayableCharacters.Count == 0)
            {
                return;
            }

            // for each character in the PlayableCharacters list
            for (int i = 0; i < PlayableCharacters.Count; i++)
            {
                // we instantiate the corresponding prefab
                PlayableCharacter instance = (PlayableCharacter)Instantiate(PlayableCharacters[i]);
                // we position it based on the StartingPosition point
                instance.transform.position = new Vector3(StartingPosition.transform.position.x + i * DistanceBetweenCharacters, StartingPosition.transform.position.y, StartingPosition.transform.position.z);
                // we set manually its initial position
                instance.SetInitialPosition(instance.transform.position);
                // we feed it to the game manager
                CurrentPlayableCharacters.Add(instance);
            }
            MMEventManager.TriggerEvent(new MMGameEvent("PlayableCharactersInstantiated"));
        }
Exemple #6
0
 /// <summary>
 /// Kills the player.
 /// </summary>
 public virtual void KillCharacter(PlayableCharacter player)
 {
     StartCoroutine(KillCharacterCo(player));
 }
 /// <summary>
 /// Clears the selected character.
 /// </summary>
 public virtual void ClearSelectedCharacter()
 {
     StoredCharacter = null;
 }
 /// <summary>
 /// Stores the selected character for use in upcoming levels
 /// </summary>
 /// <param name="selectedCharacter">Selected character.</param>
 public virtual void StoreSelectedCharacter(PlayableCharacter selectedCharacter)
 {
     StoredCharacter = selectedCharacter;
 }