Toybox Trouble

Toybox Trouble is one of my first multiplayer attempts where the Players compete with others in a series of mini-games to win as many titles as possible!
We worked here with the plugin from Photon, and I did it myself incorporated into the plugin to create appropriate scripts.

My tasks:

-Gameplay Programmer: Player controllers for the different games. -System Programmer: Implementation of the multiplayer system in the different games.

Download-Link: Toybox Trouble
oder
Play directly on this website: Toybox Trouble



using UnityEngine;
using Photon.Pun;
using UnityEngine.UI;

public class Login : MonoBehaviourPunCallbacks
{
	[SerializeField] GameObject lobbyConnectButton;
	[SerializeField] InputField nameInput;

	public override void OnConnectedToMaster()
	{
		PhotonNetwork.AutomaticallySyncScene = true;
		lobbyConnectButton.SetActive(true);

		if (PlayerPrefs.HasKey("NickName"))
		{
			if (PlayerPrefs.GetString("NickName") == "")
			{
				PhotonNetwork.NickName = "Player" + Random.Range(1, 1000);
			}
			else
			{
				PhotonNetwork.NickName = PlayerPrefs.GetString("NickName");
			}
		}
		else
		{
			PhotonNetwork.NickName = "Player" + Random.Range(1, 1000);
		}
		nameInput.text = PhotonNetwork.NickName;
		Debug.Log(nameInput.ToString());
	}

	public void PlayerNameInput(string nameInput)
	{
		PhotonNetwork.NickName = nameInput;
		PlayerPrefs.SetString("NickName", nameInput);
	}

	public void ExitGame()
	{
		GamesState.TryToChange(States.Quit);
	}

	public void LobbyJoin()
	{
		GamesState.TryToChange(States.Menu);
	}
}

using Photon.Pun;
using Photon.Realtime;
using System.Collections.Generic;
using UnityEngine;

public class LobbyController : MonoBehaviourPunCallbacks
{
    [SerializeField] GameObject lobbyPanel;

    private string roomName;
    private int roomSize = 4;

    private List roomListing;
    [SerializeField] Transform container;
    [SerializeField] GameObject roomListingPrefab;

    private void Start()
    {
        roomListing = new List();
    }

    public override void OnRoomListUpdate(List roomList)
    {
        int index;
        foreach (RoomInfo room in roomList)
        {
            if (roomListing != null)
            {
                index = roomListing.FindIndex(ByName(room.Name));
            }
            else
            {
                index = -1;
            }
            if (index != -1)
            {
                roomListing.RemoveAt(index);
                Destroy(container.GetChild(index).gameObject);
            }
            if (room.PlayerCount > 0)
            {
                roomListing.Add(room);
                ListRoom(room);
            }
        }
    }

    static System.Predicate ByName(string name)
    {
        return delegate (RoomInfo room)
        {
            return room.Name == name;
        };
    }

    private void ListRoom(RoomInfo room)
    {
        if (room.IsOpen && room.IsVisible)
        {
            GameObject tempListing = Instantiate(roomListingPrefab, container);
            RoomButton tempButton = tempListing.GetComponent();
            tempButton.SetRoom(room.Name, room.MaxPlayers, room.PlayerCount);
        }
    }

    public void OnRoomNameChange(string nameIn)
    {
        roomName = nameIn;
    }

    public void CreateRoom()
    {
        Debug.Log("Create room");
        gameObject.GetComponent().ChooseRandomButthurt();
        RoomOptions roomOps = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = (byte)roomSize };
        PhotonNetwork.CreateRoom(roomName, roomOps);
    }

    public override void OnCreateRoomFailed(short returnCode, string message)
    {
        Debug.Log("There must be a room with the same name");
    }

    public void ExitGame()
    {
        GamesState.TryToChange(States.Quit);
    }
}

using UnityEngine;
using Photon.Pun;

public class NetworkController : MonoBehaviourPunCallbacks
{
    void Start()
    {
        PhotonNetwork.ConnectUsingSettings();
    }

    public override void OnConnectedToMaster()
    {
        Debug.Log("We are now connected to the " + PhotonNetwork.CloudRegion + "server");
    }
}