14: Completing the game

Step 1:
Create a new scene to act as your win scene. Save it and place it in your build settings along with your game and start screen.  File > Build Settings.
quest014 01
You can add the scenes by dragging them from the project window. Make a note of the scene number. Thie first secene in the list or Scene 0 will be the first to play.
quest014 02

Step 2:
Now we can edit the interactionScript to load the win screen when the 5th box is opened.

JS

#pragma strict

var B : GameObject;
private var COMP : float;

private var PROGRESS : float;
var bar : GameObject;
var messageDisplay : UI.Text;
private var collectedClues : int;

function Start () 
{
    B.SetActive(false);
    COMP = 0;
    PROGRESS = COMP/100;
    bar.transform.localScale = new Vector3(PROGRESS,bar.transform.localScale.y,bar.transform.localScale.z);
     messageDisplay.text = "A box is straight in front of you. It may hold a clue.";
    collectedClues = 1;
    gameObject.GetComponent(boxControl).ShowBox(collectedClues);


}

function OnTriggerStay(hit : Collider)
{
     if(hit.gameObject.tag == "BOX")
     {
           if(Input.GetButtonDown("Interact"))
          {
               var ani : Animator = hit.gameObject.GetComponent(Animator);
               ani.SetBool("OPEN", true);
               var AS : AudioSource = hit.gameObject.GetComponent(AudioSource);
               AS.Play();
              COMP += 20;
              PROGRESS = COMP/100;
              bar.transform.localScale = new Vector3(PROGRESS,bar.transform.localScale.y,bar.transform.localScale.z);
              messageDisplay.text = hit.gameObject.GetComponent(messageScript).message;
              collectedClues += 1;
              gameObject.GetComponent(boxControl).ShowBox(collectedClues);
              if(collectedClues == 6)
              {
                   WinGame();
              }
               Destroy(hit.gameObject.GetComponent(Collider));
               B.SetActive(false);

          }
     }
}

function OnTriggerEnter(hit : Collider)
{
    if(hit.gameObject.tag == "BOX")
    {
        B.SetActive(true);
    }

}


function OnTriggerExit(hit : Collider)
{
    if(hit.gameObject.tag == "BOX")
    {
        B.SetActive(false);
    }
}

function WinGame()
{
     yield WaitForSeconds(5);
     Application.LoadLevel(2);
}

C#

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

public class interactionControls : MonoBehaviour {

public GameObject B;
float COMP;

float PROGRESS;
public GameObject bar;
public Text messageDisplay;
int collectedClues;

// Use this for initialization
void Start ()
{

     B.SetActive(false);
     COMP = 0;
     PROGRESS = COMP/100;
     bar.transform.localScale = new Vector3(PROGRESS,bar.transform.localScale.y,bar.transform.localScale.z);
   messageDisplay.text = "A box is straight in front of you. It may hold a clue.";
    collectedClues = 1;
    gameObject.GetComponent<boxControl>().ShowBox(collectedClues);


}


void OnTriggerStay(Collider hit)
{

     if(hit.gameObject.tag == "BOX")
     {
          if(Input.GetButtonDown("Interact"))
          {
               Animator ani = hit.gameObject.GetComponent<Animator>();
               ani.SetBool("OPEN", true);
               AudioSource AS  = hit.gameObject.GetComponent<AudioSource>();
               AS.Play();
              COMP += 20;
              PROGRESS = COMP/100;
              bar.transform.localScale = new Vector3(PROGRESS,bar.transform.localScale.y,bar.transform.localScale.z);
       messageDisplay.text = hit.gameObject.GetComponent(messageScript).message;
              collectedClues += 1;
              gameObject.GetComponent<boxControl>().ShowBox(collectedClues);
              if(collectedClues == 6)
              {
                   WinGame();
              }
               Destroy(hit.gameObject.GetComponent<Collider>());
               B.SetActive(false);

          }
     }
}

void OnTriggerEnter(Collider hit)
{
     if(hit.gameObject.tag == "BOX")
     {
          B.SetActive(true);
     }
}

void OnTriggerExit(Collider hit)
{
     if(hit.gameObject.tag == "BOX")
     {
          B.SetActive(false);
     }

}

}

void WinGame()
{
     yield WaitForSeconds(5);
     Application.LoadLevel(2);
}

Casino Bet 365 is best casino in the world.

What's Next

Next up for Unity Snippets is a look at game development articles from across the web...

Free Templates - bigtheme.net
Popular Art Betting make bookies articles.