-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkController.cs
More file actions
51 lines (45 loc) · 1.25 KB
/
NetworkController.cs
File metadata and controls
51 lines (45 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
#if UNITY_EDITOR
using ParrelSync;
#endif
using TMPro;
using Unity.Netcode;
using UnityEngine;
/**
* Manages the Network by starting host or client
*/
public class NetworkController : MonoBehaviour {
[SerializeField] private TextMeshProUGUI status;
[SerializeField] private GameObject hostButton;
[SerializeField] private GameObject clientButton;
// if true,
// for unity playmode a host is started automatically
// for a normal build a client is started automatically
[SerializeField] private Boolean autoConnect = false;
public void StartHost() {
NetworkManager.Singleton.StartHost();
status.text = "Host";
hostButton.SetActive(false);
clientButton.SetActive(false);
}
public void StartClient() {
NetworkManager.Singleton.StartClient();
status.text = "Client";
hostButton.SetActive(false);
clientButton.SetActive(false);
}
private void Start() {
if (autoConnect) {
#if UNITY_EDITOR
if (ClonesManager.IsClone()) {
StartClient();
}
else {
StartHost();
}
#else
StartClient();
#endif
}
}
}