반응형
- 코드 작성
using System;
using System.Collections;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine.UI;
public class NetworkManager : MonoBehaviourPunCallbacks
{
int hp = 100;
public Text hpText;
public PhotonView PV;
private void Start()
{
StartTimer();
}
void StartTimer()
{
if(PhotonNetwork.IsMasterClient)
{
hp = 100;
StartCoroutine(TimerCoroution());
}
}
IEnumerator TimerCoroution()
{
if(hp > 0)
{
hp -= 1;
}
else
{
Debug.Log("게임 종료");
yield break;
}
PV.RPC("ShowHpBar", RpcTarget.All, hp); //1초 마다 방 모두에게 전달
yield return new WaitForSeconds(1);
StartCoroutine(TimerCoroution());
}
[PunRPC]
void ShowHpBar(int number)
{
hpText.text = number.ToString(); //체력 갱신
}
}
반응형