﻿using BeardedManStudios.Network;
using UnityEngine;

namespace Dissonance.Integrations.ForgeNetworking.Demo
{
    public class PlayerSpawner
        : MonoBehaviour
    {
        public GameObject ObjectToSpawn;

        private void Start()
        {
            // This will buffer spawn the cube across the Network for each client
            if (BeardedManStudios.Network.Networking.PrimarySocket.Connected)
                BeardedManStudios.Network.Networking.Instantiate(ObjectToSpawn, NetworkReceivers.AllBuffered);
            else
            {
                BeardedManStudios.Network.Networking.PrimarySocket.connected += () =>
                {
                    BeardedManStudios.Network.Networking.Instantiate(ObjectToSpawn, NetworkReceivers.AllBuffered);
                };
            }
        }
    }
}
