Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Unity.Netcode;
- public class GameManager : NetworkBehaviour
- {
- //---- Network ----//
- [SerializeField]private NetworkManager networkManager;
- [SerializeField]private NetworkPrefabsList networkPrefabsList;
- //---- Spawn System ----//
- //0 = BoyTeacher, 1 = GirlTeacher, 2 = BoyStudent, 3 = GirlStudent
- private int playerTypeId;
- [SerializeField] private Transform[] teacherSpawnPosition;
- [SerializeField] private Transform[] studentSpawnPosition;
- //---- Debug ----//
- [SerializeField]private bool debugIO = false;
- // Start is called before the first frame update
- void Start()
- {
- //GetComponent<NetworkObject>().Spawn();
- }
- //==== On Network Spawn ====//
- public override void OnNetworkSpawn()
- {
- GmDebugger("On Network Spawn");
- if (IsHost || IsClient) SpawnPlayerServerRpc();
- }
- //==== Start Host Button
- public void StartHostButton(int _playerTypeId)
- {
- GmDebugger("Host Started");
- playerTypeId = _playerTypeId;
- networkManager.StartHost();
- //this.GetComponent<NetworkObject>().Spawn();
- }
- //==== Start Client Button
- public void StartClientButton(int _playerTypeId)
- {
- GmDebugger("Client Started");
- playerTypeId = _playerTypeId;
- networkManager.StartClient();
- //this.GetComponent<NetworkObject>().Spawn();
- }
- //==== Start Server Button
- public void StartServerButton(int _playerTypeId)
- {
- GmDebugger("Server Started");
- playerTypeId = _playerTypeId;
- networkManager.StartServer();
- }
- //==== player Spawn System ====//
- [ServerRpc(RequireOwnership = false)]
- public void SpawnPlayerServerRpc() {
- Debug.Log(networkPrefabsList.PrefabList[playerTypeId].Prefab);
- GameObject NetPlayerPrefabClone = Instantiate(networkPrefabsList.PrefabList[playerTypeId].Prefab);
- if(playerTypeId < 2) NetPlayerPrefabClone.transform.position = teacherSpawnPosition[0].position;
- if(playerTypeId > 1) NetPlayerPrefabClone.transform.position = studentSpawnPosition[0].position;
- NetPlayerPrefabClone.GetComponent<NetworkObject>().Spawn();
- //networkManager.AddNetworkPrefab(networkPrefabsList.PrefabList[playerTypeId.Value].Prefab);
- }
- //==== Game Manager Debugger ====//
- public void GmDebugger(object debugObj) {
- if (debugIO) Debug.Log(debugObj);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement