Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using Photon.Pun;
- using System.Collections.Generic;
- using TMPro;
- using PlayFab;
- using PlayFab.ClientModels;
- public class LevelManager : MonoBehaviourPunCallbacks
- {
- public GameObject player;
- public GameObject mainCamera;
- public GameObject escapeMenu;
- public GameObject errorPanel;
- public List<GameObject> spawnpointList = new List<GameObject>();
- public TMP_Text timerText;
- [SerializeField] private float timer;
- [HideInInspector] public bool escapeMenuOpen;
- string playerName;
- private SceneToLoad sceneToLoad;
- private int randomNumber;
- private void Awake()
- {
- GetAccountInfo();
- }
- void Start()
- {
- sceneToLoad = FindObjectOfType<SceneToLoad>();
- escapeMenu.SetActive(false);
- Cursor.lockState = CursorLockMode.Locked;
- Spawn();
- }
- void Update()
- {
- timer -= Time.deltaTime;
- int minutes = Mathf.FloorToInt(timer / 60F);
- int seconds = Mathf.FloorToInt(timer - minutes * 60);
- timerText.text = string.Format("{0:0}:{1:00}", minutes, seconds);
- if (Input.GetKeyDown(KeyCode.Escape))
- {
- EscapeMenuOpen();
- }
- }
- void GetAccountInfo()
- {
- var request = new GetAccountInfoRequest();
- PlayFabClientAPI.GetAccountInfo(request, OnAccountInfoSuccess, OnError);
- }
- private void OnAccountInfoSuccess(GetAccountInfoResult result)
- {
- playerName = result.AccountInfo.TitleInfo.DisplayName;
- }
- private void OnError(PlayFabError error)
- {
- errorPanel.SetActive(true);
- }
- void RandomNumber()
- {
- randomNumber = Random.Range(0, spawnpointList.Count);
- Spawn();
- }
- public void Spawn()
- {
- bool dontSpawn = spawnpointList[randomNumber].GetComponent<ColliderOccupied>().occupied;
- if(!dontSpawn)
- {
- Vector3 randomspawnPoint = spawnpointList[randomNumber].GetComponent<Transform>().position;
- player = PhotonNetwork.Instantiate("Player", randomspawnPoint, Quaternion.identity, 0);
- mainCamera.GetComponent<CameraFollow>().target = player.transform;
- PhotonNetwork.NickName = playerName;
- } else
- {
- RandomNumber();
- }
- }
- public void Logout()
- {
- PlayFabClientAPI.ForgetAllCredentials();
- PhotonNetwork.Disconnect();
- sceneToLoad.sceneToLoad = "Login";
- SceneManager.LoadScene("MenuLoading");
- }
- void EscapeMenuOpen()
- {
- if (escapeMenu.activeSelf)
- {
- escapeMenuOpen = false;
- escapeMenu.SetActive(false);
- player.GetComponent<PlayerMovement>().enabled = true;
- player.GetComponent<Shooting>().enabled = true;
- Cursor.lockState = CursorLockMode.Locked;
- }
- else
- {
- escapeMenuOpen = true;
- escapeMenu.SetActive(true);
- player.GetComponent<PlayerMovement>().enabled = false;
- player.GetComponent<Shooting>().enabled = false;
- Cursor.lockState = CursorLockMode.None;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement