본문 바로가기
개발/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
{

    int towerHp = 100;


    bool isRaining = false;


    public PhotonView PV;


    void AttackTower()
    {
        PV.RPC("HitTower", RpcTarget.All); //방 전체 사람들에게 타워 체력 -10

        PV.RPC("HitTower", RpcTarget.All, 10);

        PV.RPC("HitTower", RpcTarget.MasterClient, 10); //방장만 타워 체력 -10

        PV.RPC("HitTower", RpcTarget.Others, 10); //나를 제외한 타워 체력 -10
    }

    void ChangeWeather()
    {
        PV.RPC("Raining", RpcTarget.All, true);
    }



    [PunRPC]
    void HitTower()
    {
        towerHp -= 10;
    }


    [PunRPC]
    void HitTower(int number)
    {
        towerHp -= number;
    }


    [PunRPC]
    void Raining(bool check)
    {
        isRaining = check;

        if (check)
        {
            Debug.Log("비가 내리고 있습니다.");
        }
        else
        {
            Debug.Log("비가 멈췄습니다.");
        }
    }
}

 


참고할만한 글

 

 

유니티 C# 포톤 커스텀 프로퍼티 간단 사용법 Photon Custom Property

코드 작성 using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; using Photon.Realtime; using UnityEngine.UI; using Hashtable = ExitGames.Client.Photon.Hashtable; public class NetworkManager : MonoBehaviourPunC

parksh3641.tistory.com

 

 

유니티 C# 포톤 소유권 제어하기 Photon Ownership

코드 작성 전 주의사항 스크립트가 달린 오브젝트의 PhotonView에서 OwnershipSphere 옵션이 TakeOver로 설정되어 있어야합니다. "Fixed" 는 게임오브젝트를 생성한 것이 지속적으로 소유자로 유지 되는 것

parksh3641.tistory.com

 

반응형

댓글