im new to UNET coding, but im learning alot , how i can use this script , make it functional ? the codes are from : https://forum.unity.com/threads/usi...fdtBnwpFj2kH_pNhVJFLnkvtrHJWPXHn3RurEDpMoPVeo Code (CSharp): using UnityEngine; using UnityEngine.Networking; using UnityEngine.Networking.NetworkSystem; public class NetworkCustom : NetworkManager { public int chosenCharacter = 0; public GameObject[] characters; //subclass for sending network messages public class NetworkMessage : MessageBase { public int chosenClass; } public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId, NetworkReader extraMessageReader) { NetworkMessage message = extraMessageReader.ReadMessage<NetworkMessage>(); int selectedClass = message.chosenClass; Debug.Log("server add with message " + selectedClass); GameObject player; Transform startPos = GetStartPosition(); if(startPos != null) { player = Instantiate(characters[chosenCharacter], startPos.position,startPos.rotation)as GameObject; } else { player = Instantiate(characters[chosenCharacter], Vector3.zero, Quaternion.identity) as GameObject; } NetworkServer.AddPlayerForConnection(conn, player, playerControllerId); } public override void OnClientConnect(NetworkConnection conn) { NetworkMessage test = new NetworkMessage(); test.chosenClass = chosenCharacter; ClientScene.AddPlayer(conn, 0, test); } public override void OnClientSceneChanged(NetworkConnection conn) { //base.OnClientSceneChanged(conn); } public void btn1() { chosenCharacter = 0; } public void btn2() { chosenCharacter = 1; } } and this code Code (CSharp): using UnityEngine; using System.Collections; using UnityEngine.Networking; public class ChooseHero : MonoBehaviour { public GameObject characterSelect; public void PickHero(int hero) { NetworkManager.singleton.GetComponent<NetworkCustom>().chosenCharacter = hero; characterSelect.SetActive(false); } }
Since Unet is deprecated and being removed from the engine in a matter of months, now is not a good time to start learning it. As per your question, you should say what is going wrong with the script when you use it. On a quick look, nothing appears to be obviously non-functional.
i didnt know UNET is about to vanish :/ i just got started learning networking , should i learn Photon instead? or would you recommend anything else?
There is Mirror, which is a community project that uses a very similar API to UNETs (was based on Unity's HLAPI open source code), and is under active development and support. https://forum.unity.com/threads/mirror-networking-for-unity-aka-hlapi-community-edition.425437/
Well for the details see the big sticky thread titled "UNet Deprecation Thread" about Unet's imminent removal. I'd link it, but it is hard to miss. What you should use depends on your game and what 3rd party services you'd also like. If you're building a dedicated server game, then Mirror would likely be a good choice. If you want a matchmaker system and clients acting as hosts, you'll have to roll your own matchmaker server and a service to connect clients hosting behind a firewall (Unity Multiplayer Service does this for Unet, but it is also deprecated, so don't start a project now that uses it). Photon provides those services.