123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System.Collections;
- using System.Collections.Generic;
- using System.Runtime.InteropServices.ComTypes;
- using UnityEngine;
-
- public class GameManager : MonoBehaviour
- {
- public static GameManager instance;
-
- public static Dictionary<int, PlayerManager> players = new Dictionary<int, PlayerManager>();
-
- public GameObject localPlayerPrefab;
- public GameObject playerPrefab;
-
-
- private void Awake()
- {
- if (instance == null)
- {
- instance = this;
- }
- else if (instance != this)
- {
- Debug.Log("Instance already exists. Destroying object !");
- Destroy(this);
- }
- }
-
- public void SpawnPlayer(int _id, string _username, Vector3 _position, Quaternion _rotation)
- {
- GameObject _player;
-
- if(_id == Client.instance.myId)
- {
- _player = Instantiate(localPlayerPrefab, _position, _rotation);
- } else
- {
- _player = Instantiate(playerPrefab, _position, _rotation);
- }
-
- _player.GetComponent<PlayerManager>().Initialize(_id, _username);
-
- players.Add(_id, _player.GetComponent<PlayerManager>());
- }
- }
|