Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by joshrwalter · Dec 07, 2017 at 09:53 PM · unity 5networkingcharacter3d modelscreation

Unity networking create & join with custom character?,

Im new to unity, sorry if this is a bad question.

What I want to happen: User selects what parts they want and pressed build. They then join server. Other users can see their player model, and likewise, the player can see other users character models.

 Selection Script 
 
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class controller : MonoBehaviour
 {
     string prevh;
     string prevl;
     public GameObject legs;
     private List<GameObject> headModels;
     public GameObject heads;
     public GameObject NewParent;
     private List<GameObject> legModels;
     Dictionary<string, int> LegDict = new Dictionary<string, int>();
     Dictionary<string, int> HeadDict = new Dictionary<string, int>();
 
 
 
 
     [SerializeField] Dropdown DropLegs;
     [SerializeField] Dropdown DropHeads;
     private void Start()
     {
         //Generate list of body parts and hide them
         legModels = new List<GameObject>();
         int x = 0;
         foreach (Transform t in legs.transform)
         {
             //Legs
             legModels.Add(t.gameObject);
             t.gameObject.SetActive(false);
             LegDict.Add(t.ToString(), x);
             x++;
             DropLegs.options.Add(new Dropdown.OptionData(t.ToString()));
         }
         //Heads
         x = 0;
         headModels = new List<GameObject>();
         foreach (Transform t in heads.transform)
         {
             t.gameObject.SetActive(false);
             headModels.Add(t.gameObject);
             HeadDict.Add(t.ToString(), x);
             x++;
             DropHeads.options.Add(new Dropdown.OptionData(t.ToString()));
 
         }
 
     }
 
     private void Update()
     {
         //Shows built parts infront of camera
 
         //Display Head
         int menuIndex = DropHeads.GetComponent<Dropdown>().value;
         List<Dropdown.OptionData> menuOptions = DropHeads.GetComponent<Dropdown>().options;
         string valueh = menuOptions[menuIndex].text;
         //Prevents from constantly updating
         if (valueh != prevh)
         {
             //Clears other models
             if (HeadDict.ContainsKey(valueh))
             {
 
                 //Hides other models
                 foreach (Transform t in heads.transform)
                 {
                     t.gameObject.SetActive(false);
                 }
                 //Displays the current model
                 headModels[HeadDict[valueh]].SetActive(true);
             }
         }
         prevh = valueh;
 
         //Repeat of the code for heads but with legs
         //Display legs
         menuIndex = DropLegs.GetComponent<Dropdown>().value;
         menuOptions = DropLegs.GetComponent<Dropdown>().options;
         string valuel = menuOptions[menuIndex].text;
         if (valuel != prevl)
         {
             if (LegDict.ContainsKey(valuel))
             {
                 foreach (Transform t in legs.transform)
                 {
                     t.gameObject.SetActive(false);
                 }
                 legModels[LegDict[valuel]].SetActive(true);
             }
         }
         prevl = valuel;
 
     }
 
     //Called when the build button is pressed.
     public void Build()
     {
         //Save The Chosen Parts to a GameObject
         GameObject myLeg = Instantiate(legs) as GameObject;
         myLeg.transform.parent = NewParent.transform;
         myLeg.transform.position = NewParent.transform.position;
         GameObject myHead = Instantiate(heads) as GameObject;
         myHead.transform.parent = NewParent.transform;
         myHead.transform.position = NewParent.transform.position;
         Debug.Log("Built Mech with head: " + prevh + " and legs: " + prevl);
     }
 
 }
 
 
 
 
 
 
 Network Script
 
 using UnityEngine;
 using UnityEngine.Networking;
 using UnityEngine.Networking.NetworkSystem;
 using UnityEngine.UI;
 
 public class MyNetManager : NetworkManager {
 
     public GameObject PlayerPrefab;
     public GameObject UI;
 
 
     public void StartupHost()
     {
         SetPort();
         NetworkManager.singleton.StartHost();
         HideUI();
     }
 
     public void HideUI()
     {
         UI.SetActive(false);
     }
     public void JoinGame()
     {
         SetIPAddress();
         SetPort();
         NetworkManager.singleton.StartClient();
         HideUI();
     }
 
     void SetIPAddress()
     {
         string ipaddress = GameObject.Find("InputFieldIPAddress").transform.Find("Text").GetComponent<Text>().text;
         NetworkManager.singleton.networkAddress = ipaddress;
     }
 
     void SetPort()
     {
         NetworkManager.singleton.networkPort = 7777;
     }
 
     private void LevelWasLoaded(int level)
     {
         if (level == 0)
         {
             Debug.Log("Loaded First");
             SetupMenuSceneButtons();
         }
         else
         {
             Debug.Log("Loaded 2nd");
             SetupOtherSceneButtons();
         }
     }
 
     void SetupMenuSceneButtons()
     {
         GameObject.Find("ButtonStartHost").GetComponent<Button>().onClick.RemoveAllListeners();
         GameObject.Find("ButtonStartHost").GetComponent<Button>().onClick.AddListener(StartupHost);
 
         GameObject.Find("ButtonJoinGame").GetComponent<Button>().onClick.RemoveAllListeners();
         GameObject.Find("ButtonJoinGame").GetComponent<Button>().onClick.AddListener(JoinGame);
     }
 
     void SetupOtherSceneButtons()
     {
         GameObject.Find("ButtonDisconnect").GetComponent<Button>().onClick.RemoveAllListeners();
         GameObject.Find("ButtonDisconnect").GetComponent<Button>().onClick.AddListener(NetworkManager.singleton.StopHost);
     }
 
     public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId, NetworkReader extraMessageReader)
     {
         int id = 0;
         if (extraMessageReader != null)
         {
             IntegerMessage i = extraMessageReader.ReadMessage<IntegerMessage>();
             id = i.value;
         }
         GameObject playerPrefab = PlayerPrefab;
         GameObject player;
         Transform startPos = GetStartPosition();
         if (startPos != null)
         {
             player = (GameObject)Instantiate(playerPrefab, startPos.position, startPos.rotation);
         }
         else
         {
             player = (GameObject)Instantiate(playerPrefab, Vector3.zero, Quaternion.identity);
         }
         NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
     }
 
 }


,

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

191 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

NetworkManager.ServerChangeScene from client to server 0 Answers

Photon Network instantiate problem when Master changes 0 Answers

New Unity 5.1 Networking :- Spawning is not synchronized!!!! 2 Answers

Best method for Skyrim-Like character customization? 1 Answer

need help with syncing ui canvas 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges