NetworkManager.cs 소스입니다
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
public class NetworkManager : MonoBehaviourPunCallbacks
{
void Awake()
{
Screen.SetResolution(960, 540, false);
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster() => PhotonNetwork.JoinOrCreateRoom("Room", new RoomOptions { MaxPlayers = 6 }, null);
public override void OnJoinedRoom()
{
PhotonNetwork.Instantiate("Player", Vector3.zero, Quaternion.identity);
}
}
PlayerScript.cs 소스입니다
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine.UI;
public class PlayerScript : MonoBehaviourPunCallbacks, IPunObservable
{
public PhotonView PV;
public SpriteRenderer SR;
public Animator AN;
public Text txt;
void Update()
{
if (PV.IsMine)
{
float axis = Input.GetAxisRaw("Horizontal");
transform.Translate(new Vector3(axis * Time.deltaTime * 7, 0, 0));
if (axis != 0)
{
PV.RPC("FlipXRPC", RpcTarget.AllBuffered, axis);
AN.SetBool("walk", true);
}
else AN.SetBool("walk", false);
}
}
[PunRPC]
void FlipXRPC(float axis)
{
SR.flipX = axis == -1;
}
[ContextMenu("더하기")]
public void Plus() => txt.text = (int.Parse(txt.text) + 1).ToString();
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting) stream.SendNext(txt.text);
else txt.text = (string)stream.ReceiveNext();
}
}