Success, Fail and Guide Screens

Next step was to create Pop-ups for when you start the game (a guide showing you the map and what you need to do), the success screen (when you do all the objectives and return to the starting location) and a fail screen (when the player dies). I used Connor’s assets, which I imported into Unity as Sprites. For the starting screen, I parented the sprite to the camera and positioned it in the right place to fit the Game Screen nicely. I also added a script to it. The Script is really simple, all it does is it tells Unity to make it active on Start, then when the Left Mouse Button is pressed, set it to inactive:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GuidePopup : MonoBehaviour 
{
    private GameObject guide;

    void Start () 
    {
        guide = GameObject.Find (DemoLevelGuide01);
        guide.SetActive (true);
    }

    void Update () 
    {
        if (Input.GetMouseButtonDown (0)) 
        {
            guide.SetActive (false);
        }
    }
}

The Death one was slightly more complicated, but not overly complicated. I’ve used the ‘PlayerStats’ script, as it contains the Health information so it made setting it up easier. First, I made a reference to the correct Pop-up object and set it to inactive by default. Then, I created a new method called Death(), which gets triggered in the if statement in the Update() method with an Invoke (delay in execution) of 5 seconds. The Death() method sets the Pop-up to active, and then if the Left Mouse Button is pressed, the SceneReload() method is executed, which reloads the scene, so the player can start again. Here’s the whole script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class PlayerStats : MonoBehaviour 
{

    private object[] stats;
    private GameObject dScreen;

    void Start () 
    {
        //Values used to calculate player activity
        stats = new object[] 
        {
            100,                                                 //0:Health
            6,                                                   //1:Ammo
            50,                                                  //2:Dimension Swap Charge
        }; 
        dScreen = GameObject.Find (UI PopUps01);
        dScreen.SetActive (false);
    }

    public void SetHealth(int newHealth) 
    {
        stats[0] = newHealth;
    }

    public void SetAmmo(int newAmmo) 
    {
        stats[1] = newAmmo;
    }

    public void SetDimCharge(int newCharge) 
    {
        stats[2] = newCharge;
    }

    public object GetStat(int index) 
    {
        return stats [index];
    } 

    void CheckValues() 
    {
        //Keeps stat values within acceptable ranges
        if ((int)stats[0] < 0) 
        {
            stats[0] = 0;
        } 
        else if ((int)stats[0] > 100) 
        {
            stats[0] = 100;
        }

        if ((int)stats[1] < 0) 
        {
            stats[1] = 0;
        } 
        else if ((int)stats[1] > 6) 
        {
            stats[1] = 6;
        }

        if ((int)stats[2] < 0) 
        {
            stats[2] = 0;
        } 
        else if ((int)stats[2] > 50) 
        {
            stats[2] = 50;
        }
            
    }

    void Death()
    {
        dScreen.SetActive(true);
        if (Input.GetMouseButtonDown (0)) 
        {
            SceneReload ();
        }
    }

    void SceneReload()
    {
        SceneManager.LoadScene (connor_buildings);
    }

    void Update () 
    {
        CheckValues ();

        if ((int)stats [0] < 0.1) 
        {
            GetComponent<Animator>().Play (Death);
            GetComponent<PlayerMove> ().enabled = false;
            GetComponent<RotationCheck> ().enabled = false;
            GetComponent<player_computer> ().enabled = false;
            GetComponent<player_button> ().enabled = false;
            GetComponent<Player_sound> ().enabled = false;
            GetComponent<player_takedown> ().enabled = false;
            GetComponent<PlayerActions> ().enabled = false;
            GetComponent<PlayerControls> ().enabled = false;
            GetComponent<player_stairs> ().enabled = false;
            Invoke (Death, 5f);
        }
    }
}

The video below shows both the starting screen and the death screen(note that the reloaded scene has really weird lighting, I looked into that issue and it is a problem with how it’s displayed inside Unity and will not occur in the build of the game):

Lastly, I have made the Mission Complete screen which I did by creating an Empty Child (named ‘MissionComplete’) with a Box Collider set to isTrigger and the trigger box was scaled correctly inside the starting room. I went back to the ‘player_computer’ script and set the new trigger box to be off by default and to only turn on after the second computer has been used.

Then I attached a script to the MissionComplete object, and made a reference to the correct Pop-up sprite and set it to inactive at the start. Then using ‘OnTriggerEnter’ with the Tag “Player”, Unity knows when the player has arrived to the starting location so it displays the pop-up, disables movement and sets the ‘canReload’ bool to true. While that bool is set to true, the player can press the Left Mouse Button to trigger the SceneReload() method, which is the same as in the script above. Here’s the whole script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class MissionComplete : MonoBehaviour 
{
    private GameObject wScreen;
    private bool canReload;

    void Start () 
    {
        wScreen = GameObject.Find (UI PopUps02);
        wScreen.SetActive (false);
        canReload = false;
    }

    void OnTriggerEnter(Collider other)
    {
        if (other.tag == Player)
        {
            GameObject.Find (JackTaylor).GetComponent<PlayerMove> ().enabled = false;
            wScreen.SetActive (true);
            canReload = true;
        }
    }

    void SceneReload()
    {
        SceneManager.LoadScene (connor_buildings);
    }

    void Update () 
    {
        if (Input.GetMouseButtonDown (0) && (canReload == true)) 
        {
            SceneReload ();
        }
    }
}

Here’s a gif of the Mission Complete screen pop-up and scene reloading after the computers have been used:

2017-05-25_00-15-58.gif

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s