Escape Temple

Published by mark on

Escape Temple

Meta Data

Teamsize: 2 devs 2 artists

Project Length: 10 weeks, 5h a week

Duties: Networking, AI, Player: movement and interaction

Engine: Unity, for networking we used Unet

first ever project i did working in unity with a small team. This project is a Escape room set inside of a temple the character got trapped in. his mission is to escape from it with help of another player “multiplayer”.

Screenshots & walkthrough

Sample Code

This project is the first i actually want to show the code because it’s not as ugly as i started in the beginning of my first year. Sample code below is of my connection menu found in as a menu you’ll be loaded into at startup.

Duties

In this project I’ve made the AI, networking, Obstical’s scripts. and also modified teammember’s scripts to make it network ready.

  using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Networking.Match;
using UnityEngine.UI;

public class network_manager_customscript : MonoBehaviour
{
    [SerializeField]
    private GameObject roomlist_item;

    private GameObject content;
    private NetworkManager netman;
    private Text viewporttext;
    private GameObject menu;
    private float timer;

    // Use this for initialization
    private void Start()
    {
        netman = NetworkManager.singleton;
        netman.StartMatchMaker();
        reload_main();
        refresh_match_list();
    }	// Update is called once per frame

    public void reload_main()
    {
        menu = GameObject.Find("menu");
        if (GameObject.Find("listlog") != null)
            viewporttext = GameObject.Find("listlog").GetComponent();
        content = GameObject.Find("Content");
        netman = NetworkManager.singleton;
        netman.StartMatchMaker();
        refresh_match_list();
    }

    public void startserver()
    {
        netman = NetworkManager.singleton;
        if (netman.matchName != "default")
        {
            netman.matchMaker.CreateMatch(netman.matchName, (uint)netman.maxConnections, true, "", "", "", 0, 0, netman.OnMatchCreate);
            Cursor.visible = false;
            Cursor.lockState = CursorLockMode.Locked;
        }
    }

    public void change_matchname(string new_name)
    {
        netman = NetworkManager.singleton;
        if (new_name != "")
            netman.matchName = new_name;
    }

    public void refresh_match_list()
    {
        netman = NetworkManager.singleton;
        if (content == null) reload_main();
        else foreach (Transform child in content.transform) Destroy(child.gameObject);
        if (viewporttext == null) reload_main();
        else viewporttext.text = "Searching for active matches!";
        NetworkManager.singleton.matchMaker.ListMatches(0, 10, "", true, 0, 0, OnInternetMatchList);
        timer = 0;
    }

    private void OnInternetMatchList(bool success, string extendedInfo, List matches)
    {
        if (success && matches.Count != 0)
        {
            foreach (MatchInfoSnapshot i in matches)
            {
                if (i.maxSize == i.currentSize) continue;
                GameObject newobj = Instantiate(roomlist_item);
                if (newobj != null)
                {
                    newobj.transform.SetParent(content.transform);
                    newobj.transform.localPosition = new Vector3(90, -20, 0);
                    newobj.GetComponent().setuptojoin(i, joinroom);
                    viewporttext.text = "";
                }
            }
        }
        else
        {
            viewporttext.text = ("No matches found!");
        }
    }

    private void OnJoinInternetMatch(bool success, string extendedInfo, MatchInfo matchInfo)
    {
        if (success)
        {
            MatchInfo hostInfo = matchInfo;
            NetworkManager.singleton.StartClient(hostInfo);
        }
        else
        {
            menu.SetActive(true);
            viewporttext.text = ("Join match failed");
            Cursor.visible = true;
            Cursor.lockState = CursorLockMode.Confined;
        }
    }

    public void joinroom(MatchInfoSnapshot info)
    {
        menu.SetActive(false);
        netman.matchMaker.JoinMatch(info.networkId, "", "", "", 0, 0, OnJoinInternetMatch);
        Cursor.visible = false;
        Cursor.lockState = CursorLockMode.Locked;
    }

    public void disconnect_from_current()
    {
        netman.matchMaker.DropConnection(netman.matchInfo.networkId, netman.matchInfo.nodeId, 0, netman.OnDropConnection);
        netman.StopHost();
        netman.StopClient();
        netman.StopMatchMaker();
    }

    private void Update()
    {
        timer += (1 * Time.deltaTime);
        if (timer > 3 && viewporttext != null)
            refresh_match_list();
    }
}
}

Workflow

We used Unity collaboration and this was the first time i and all other members were using version control software, so at that time, some things didn’t go so well. but it was a nice welcoming experience that i learned a lot from.

Categories: Project