0% found this document useful (0 votes)
33 views4 pages

Game Manager Script

This script manages gameplay in a multiplayer scene. It handles spawning players at random bases on join, tracks the player count, and calls scene loading on leave. It uses Photon networking for multiplayer functionality like joining/leaving rooms and instantiating player prefabs.

Uploaded by

Chethan J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views4 pages

Game Manager Script

This script manages gameplay in a multiplayer scene. It handles spawning players at random bases on join, tracks the player count, and calls scene loading on leave. It uses Photon networking for multiplayer functionality like joining/leaving rooms and instantiating player prefabs.

Uploaded by

Chethan J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Game Manager script

using Photon.Pun;

using Photon.Realtime;

using UnityEngine;

using UnityEngine.SceneManagement;

public class GameManager : MonoBehaviourPunCallbacks

public static GameManager instance;

[SerializeField]

private GameObject playerPrefab;

[SerializeField]

private Transform[] playerBases;

int i = 0;

int n;

public int spawnPoint;

public int playerCount;

private void Awake()

if (instance != null)

Destroy(this.gameObject);

1
}

else

instance = this;

// Start is called before the first frame update

void Start()

spawnPoint = Random.Range(i, playerBases.Length - 1);

if (PhotonNetwork.IsConnected)

if (playerPrefab != null)

PhotonNetwork.Instantiate(playerPrefab.name,
playerBases[spawnPoint].position + new Vector3(0f, 50f, 1f),
Quaternion.identity);

playerBases[spawnPoint].GetComponentInChildren<Light>
().gameObject.SetActive(true);

else

Debug.LogError("missing player prefab");

2
}

// Update is called once per frame

void Update()

public override void OnJoinedRoom()

Debug.Log(PhotonNetwork.NickName + " joined to " +


PhotonNetwork.CurrentRoom.Name);

public override void OnPlayerEnteredRoom(Player newPlayer)

Debug.Log(newPlayer.NickName + " joined to " +


PhotonNetwork.CurrentRoom.Name + " " +
PhotonNetwork.CurrentRoom.PlayerCount);

public override void OnLeftRoom()

SceneManager.LoadScene(0);

3
public void LeaveRoom()

PhotonNetwork.LeaveRoom();

You might also like