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

public class CreateAndJoinRooms : MonoBehaviourPunCallbacks
{
    public TMP_InputField createInput;
    public TMP_InputField joinInput;
    public TMP_InputField playerCount;

    public void CreateRoom()
    {
        if (!String.IsNullOrEmpty(playerCount.text))
        {
            RoomOptions roomOptions = new RoomOptions();
            int temp = 2;
            int.TryParse(playerCount.text, out temp);
            roomOptions.MaxPlayers = (byte)temp;
            PhotonNetwork.CreateRoom(createInput.text, roomOptions);
        }
        else
        {
            RoomOptions roomOptions = new RoomOptions();
            roomOptions.MaxPlayers = 2;
            PhotonNetwork.CreateRoom(createInput.text, roomOptions);
        }
    }

    public void JoinRoom()
    {
        PhotonNetwork.JoinRoom(joinInput.text);
    }

    public override void OnJoinedRoom()
    {
        PhotonNetwork.LoadLevel("Game");
    }
}