Test de communication de paquets entre un client et un serveur
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

GameManager.cs 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices.ComTypes;
  4. using UnityEngine;
  5. public class GameManager : MonoBehaviour
  6. {
  7. public static GameManager instance;
  8. public static Dictionary<int, PlayerManager> players = new Dictionary<int, PlayerManager>();
  9. public GameObject localPlayerPrefab;
  10. public GameObject playerPrefab;
  11. private void Awake()
  12. {
  13. if (instance == null)
  14. {
  15. instance = this;
  16. }
  17. else if (instance != this)
  18. {
  19. Debug.Log("Instance already exists. Destroying object !");
  20. Destroy(this);
  21. }
  22. }
  23. public void SpawnPlayer(int _id, string _username, Vector3 _position, Quaternion _rotation)
  24. {
  25. GameObject _player;
  26. if(_id == Client.instance.myId)
  27. {
  28. _player = Instantiate(localPlayerPrefab, _position, _rotation);
  29. } else
  30. {
  31. _player = Instantiate(playerPrefab, _position, _rotation);
  32. }
  33. _player.GetComponent<PlayerManager>().Initialize(_id, _username);
  34. players.Add(_id, _player.GetComponent<PlayerManager>());
  35. }
  36. }