게임 메니저
using UnityEngine;
using Photon.Pun;
public class GameManager : MonoBehaviourPunCallbacks
{
private void Start()
{
// Photon 서버에 연결
PhotonNetwork.ConnectUsingSettings();
}
public override void OnConnectedToMaster()
{
// 마스터 서버에 연결되었을 때 실행될 코드
Debug.Log("Connected to Photon server.");
// 룸(게임 세션)에 입장
PhotonNetwork.JoinRandomRoom();
}
public override void OnJoinRandomFailed(short returnCode, string message)
{
// 빈 룸을 찾을 수 없을 때 실행될 코드
Debug.Log("Failed to join a room. Creating a new room.");
// 새로운 룸 생성
PhotonNetwork.CreateRoom(null, new Photon.Realtime.RoomOptions { MaxPlayers = 2 });
}
public override void OnJoinedRoom()
{
// 룸에 입장했을 때 실행될 코드
Debug.Log("Joined a room.");
// 플레이어 생성
PhotonNetwork.Instantiate("Player", Vector3.zero, Quaternion.identity);
}
}
포톤 메니저
using UnityEngine;
using Photon.Pun;
public class PhotonManager : MonoBehaviourPunCallbacks
{
private void Awake()
{
// Photon 초기화
PhotonNetwork.AutomaticallySyncScene = true;
}
}
플레이어 이동
using UnityEngine;
using Photon.Pun;
public class PlayerCtrl : MonoBehaviourPun
{
public float moveSpeed = 5f;
private void Update()
{
if (!photonView.IsMine) return;
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
// 플레이어 이동
transform.Translate(new Vector3(horizontalInput, 0, verticalInput) * moveSpeed * Time.deltaTime);
}
}
카메라 이동은 다음 시간에 리뷰하겠습니다
멀티확인