BeardedManStudios / ForgeNetworkingRemastered

See various forks, also please join the Forge Community fork of Forge Alloy! -> https://github.com/ForgeAlloyCommunity/ForgeAlloy
https://twitter.com/FarrisFaulds
Apache License 2.0
1.49k stars 309 forks source link

The type or namespace name 'Networking' could not be found #334

Closed tarunkhatri closed 4 years ago

tarunkhatri commented 4 years ago

I am trying to make linux executable headless server file but i am facing this error - "The type or namespace name 'Networking' could not be found (are you missing a using directive or an assembly reference?)"

I am using Unity 2018.4.9 Personal edition. I have successfully made Moving Cube example but not able to make Linux Server file. Please help me.

My Code

`using UnityEngine; using BeardedManStudios.Network; using BeardedManStudios.Forge.Networking;

if UNITY_EDITOR && !UNITY_WEBPLAYER

using System.Collections;

endif

namespace BeardedManStudios.Network.Unity { public class StartHeadlessLinux : MonoBehaviour { public string host = "127.0.0.1"; // IP address public int port = 15937; // Port number public Networking.TransportationProtocolType protocolType = Networking.TransportationProtocolType.UDP; // Communication protocol public int playerCount = 31; // Maximum player count -- excluding this server public string sceneName = "Game"; // Scene to load public bool proximityBasedUpdates = false; // Only send other player updates if they are within range public float proximityDistance = 5.0f; // The range for the players to be updated within

    private NetWorker socket = null;                                                                        // The initial connection socket

    private void Awake()
    {
        DontDestroyOnLoad(gameObject);
    }

    public void Start()
    {
        StartServer();
    }

    /// <summary>
    /// This method is called when the host server button is clicked
    /// </summary>
    public void StartServer()
    {
        // Create a host connection
        socket = Networking.Host((ushort)port, protocolType, playerCount, false);
        Go();
    }

    private void Go()
    {
        if (proximityBasedUpdates)
            socket.MakeProximityBased(proximityDistance);

        socket.serverDisconnected += delegate (string reason)
        {
            MainThreadManager.Run(() =>
            {
                Debug.Log("The server kicked you for reason: " + reason);
                Application.Quit();

if UNITY_EDITOR

                UnityEditor.EditorApplication.isPlaying = false;

endif

            });
        };

        if (socket.Connected)
            MainThreadManager.Run(LoadScene);
        else
            socket.connected += LoadScene;
    }

    private void LoadScene()
    {
        Networking.SetPrimarySocket(socket);
        Application.LoadLevel(sceneName);
    }
}

}`

NFMynster commented 4 years ago

Seems like you have looked at the old docs. the Networking.Host etc is from Forge Classic. Have a look at the wiki on this repository to get started. Also, please join the Discord if you like, as that's were most realtime support happens