본문 바로가기
개발/Photon

유니티 C# 포톤 방 참가 퇴장 알림 간단 구현 Photon RPC

by SPNK 2022. 12. 22.
반응형
  • 코드 작성
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine.UI;

public class NetworkManager : MonoBehaviourPunCallbacks
{

    public Text notionText;

    public PhotonView PV;


    private void Awake()
    {
        PV = GetComponent<PhotonView>();
    }


    public override void OnPlayerEnteredRoom(Player newPlayer)
    {
        PV.RPC("NotionRPC", RpcTarget.All, newPlayer.NickName + "님이 참가하셨습니다.");
    }

    public override void OnPlayerLeftRoom(Player otherPlayer)
    {
        PV.RPC("NotionRPC", RpcTarget.All, otherPlayer.NickName + "님이 퇴장하셨습니다.");
    }

    [PunRPC]
    void NotionRPC(string msg)
    {
        Debug.Log(msg);

        notionText.text = msg;
    }
}

 


  • 포톤 공식 Api 참고

https://doc.photonengine.com/ko-kr/pun/v1/gameplay/rpcsandraiseevent

 

RPCs 와 RaiseEvent | Photon Engine

 

doc.photonengine.com

 

반응형

댓글