Advertisement
Wyv3rn

Untitled

Feb 18th, 2023
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using FishNet.Object;
  2. using FishNet.Object.Synchronizing;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6.  
  7. public class GamePlayManager : NetworkBehaviour
  8. {
  9.  
  10.     public static GamePlayManager Instance;
  11.  
  12.     // Synct Objecte im netzwerk
  13.     [field: SyncObject]
  14.     public readonly SyncList<Player> players = new SyncList<Player>();
  15.  
  16.     [SerializeField]
  17.     GameObject playerModel; // Dev later localPlayerdta
  18.  
  19.     bool canSpawn = true;
  20.  
  21.     private void Awake()
  22.     {
  23.         Instance = this;
  24.     }
  25.  
  26.     private void Update()
  27.     {
  28.         if(IsServer)
  29.         {
  30.             return;
  31.         }
  32.  
  33.         if (canSpawn)
  34.         {
  35.             Debug.Log("I can spawn");
  36.             SpawnNewItem();
  37.             canSpawn = false;
  38.         }
  39.     }
  40.  
  41.     [Server]
  42.     void SpawnNewItem()
  43.     {
  44.         Debug.Log("Spawn!");
  45.         GameObject Player = Instantiate(playerModel);
  46.         // ownership to Player
  47.         ServerManager.Spawn(Player, players[0].Owner);
  48.     }
  49.  
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement