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 /
  • Help Room /
avatar image
0
Question by xfoo · Jan 08, 2016 at 05:12 PM · networkingnetworkclient-servermmo

Adding Clients after Log in

So I'm gonna try to make the question as small as possible. I'm currently at the early stages of developing a MMO game with Unity (2D tile based game). Now I didn't want to wait to long with the networking part to prevent difficulties, however I can't resolve the simple ones either. So I'm here for help.

What I want is basically:

  • A sign in form, simple version -> an add client button

  • A start server, simple version -> a start server button

Setting up the server seems to work, connecting with the client seems to work too. Connecting the buttons and all that stuff works. Loading the following scene works, however it lacks a player with a camera. The default way to do it results in a faulty rotation, which is what I want to solve (and ofcourse later on I want to do input checking and database calls, but that's not the thing I'm stuck on.

The player rotation gets reset by default, it does not instantiate the player with the prefab rotation, but it gets reset.

So I made my own C# class MyNetworkManager derived from the NetworkManager class.

When I start the server:

 public void StartUpServer()
     {
         NetworkManager.singleton.networkPort = 7777;
         NetworkManager.singleton.networkAddress = "127.0.0.1";
         NetworkManager.singleton.StartServer();
  }

When I start a client:

 public void StartUpClient()
 {
         NetworkManager.singleton.networkPort = 7777;
         NetworkManager.singleton.networkAddress = "127.0.0.1";
         NetworkManager.singleton.StartClient();
         SceneManager.LoadScene("PlayersRoom"); 
         // This should go to the first map (later to the saved position, but for now)
 }

So how do I get my player correctly added? The following code doesn't seem to work at all:

  public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
     {
         Debug.Log("Adding player" + playerControllerId);
         Network.Instantiate(playerPrefab, new Vector3(0, 0, 0), Quaternion.Euler(new Vector4(90, 0, 0, 0)), 0);
     }

It's not that easy to find a specific tutorial on this matter. Most people just explain how to use the default built in Networkmanager, they make a client and server and there they stop. I think I watched most of the youtube videos by now, but I think that code can be way more explaining then some tutorials.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by seanr · Jan 11, 2016 at 03:57 PM

Network.Instantiate is from the old/legacy network API. It does not work with UNet.

use "NetworkServer.AddPlayerForConnection"

http://docs.unity3d.com/Manual/UNetManager.html

Comment
Add comment · Share
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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Best way to learn Networking in general 0 Answers

UNET - Both client and server player disappears for client after scene load 0 Answers

UNet Queries 1 Answer

Issuing SetClientReady causes duplicate network objects on local client 1 Answer

How should I verify that all of my client Object are created and ready after loading a new scene? 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