Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Photon.Pun;
- using Photon.Realtime;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- public class GameManager : MonoBehaviourPunCallbacks, IPunObservable
- {
- public Text PlayerHitPointsText;
- public Text EnemyHitPointsText;
- private int PlayerHitpoints;
- private int EnemyHitpoints;
- public GameObject PlayerPrefab;
- // Use this for initialization
- void Start () {
- PlayerHitpoints = 3;
- Vector3 pos = new Vector3(Random.Range(-5f, 5f), Random.Range(-5f, 5f));
- PhotonNetwork.Instantiate(PlayerPrefab.name, pos, Quaternion.identity);
- }
- // Update is called once per frame
- void Update () {
- PlayerHitPointsText.text = "Health: " + PlayerHitpoints;
- EnemyHitPointsText.text = "Enemy health: " + EnemyHitpoints;
- if(PlayerHitpoints == 0 && PhotonNetwork.NetworkClientState == ClientState.Joined)
- {
- PhotonNetwork.LeaveRoom();
- }
- }
- public override void OnLeftRoom()
- {
- SceneManager.LoadScene(0);
- }
- public override void OnPlayerEnteredRoom(Player newPlayer)
- {
- Debug.LogFormat("Player {0} entered", newPlayer.NickName);
- }
- public override void OnPlayerLeftRoom(Player otherPlayer)
- {
- Debug.LogFormat("Player {0} left", otherPlayer.NickName);
- }
- public void Leave()
- {
- PhotonNetwork.LeaveRoom();
- }
- public void PlayerHitPointsReduce()
- {
- PlayerHitpoints -= 1;
- }
- public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
- {
- if (stream.IsWriting)
- {
- stream.SendNext(PlayerHitpoints);
- }
- else if(stream.IsReading)
- {
- EnemyHitpoints = (int)stream.ReceiveNext();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement