Beispiel #1
0
 void Start()
 {
     if (isServer)
     {
         idCount++;
         id = idCount;
     }
     if (isPlayer)
     {
         id = 0;
     }
     objSync  = new ObjectSync(id, prefabId);
     position = new PositionSync(id, transform.position);
     rotation = new RotationSync(id, transform.rotation);
     if (!isServer)
     {
         ViewerManager.instance.synchronizables.Add(this);
     }
     if (isServer)
     {
         StartCoroutine(SyncPos());
         StartCoroutine(SyncRot());
         NetworkManager.instance.SendJSON("newenemy", JsonUtility.ToJson(objSync));
     }
 }
Beispiel #2
0
        public void Receive_Kill(SocketIOEvent e)
        {
            ObjectSync objSync = JsonUtility.FromJson <ObjectSync> (e.data.ToString());

            // Kill the game object using the JSON's id.
            for (int i = 0; i < synchronizables.Count; i++)
            {
                if (synchronizables [i].id == objSync.id)
                {
                    Destroy(synchronizables [i].gameObject);
                }
            }
        }
Beispiel #3
0
        public void Receive_Spawn(SocketIOEvent e)
        {
            ObjectSync objSync = JsonUtility.FromJson <ObjectSync> (e.data.ToString());
            // Create the game object using the JSON's prefabId
            GameObject     obj  = Instantiate(enemyPrefabs [objSync.prefabId]);
            Synchronizable sync = obj.GetComponent <Synchronizable> ();

            sync.isServer = false;
            sync.id       = objSync.id;
            // Destroy Enemy component if it exists.
            Enemy enemy = obj.GetComponent <Enemy> ();

            if (enemy != null)
            {
                Destroy(enemy);
            }
        }