Test de communication de paquets entre un client et un serveur
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

NetworkManager.cs 872B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class NetworkManager : MonoBehaviour
  5. {
  6. public static NetworkManager instance;
  7. public GameObject playerPrefab;
  8. private void Awake()
  9. {
  10. if (instance == null)
  11. {
  12. instance = this;
  13. }
  14. else if (instance != this)
  15. {
  16. Debug.Log("Instance already exists, destroying object !");
  17. Destroy(this);
  18. }
  19. }
  20. private void Start()
  21. {
  22. QualitySettings.vSyncCount = 0;
  23. Application.targetFrameRate = 30;
  24. Server.Start(10, 26950);
  25. }
  26. private void OnApplicationQuit()
  27. {
  28. Server.Stop();
  29. }
  30. public Player InstantiatePlayer()
  31. {
  32. return Instantiate(playerPrefab, new Vector3(0f, 0.5f, 0f), Quaternion.identity).GetComponent<Player>();
  33. }
  34. }