Unity Photon Pun2 Multiplayer Setup || Photon Connection Establishment Code 2024

Поділитися
Вставка
  • Опубліковано 8 вер 2024

КОМЕНТАРІ • 1

  • @paradise_hope
    @paradise_hope  3 місяці тому

    ///NetworkManager.cs
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Photon.Pun;
    using Photon.Realtime;
    public class NetworkManager : MonoBehaviourPunCallbacks
    {
    void Start()
    {
    Connect();
    }
    public void Connect()
    {
    PhotonNetwork.ConnectUsingSettings();
    }
    public void Play()
    {
    PhotonNetwork.JoinRandomRoom();
    }
    public override void OnJoinRandomFailed(short returnCode, string message)
    {
    Debug.Log("Tried to join a room and failed");
    PhotonNetwork.CreateRoom(null, new RoomOptions { MaxPlayers = 4 });
    }
    public override void OnJoinedRoom()
    {
    Debug.Log("Joined a Room ---yay");
    }
    void Update()
    {
    // Add any additional update logic if needed
    }
    }