Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by TheRichardGamer · Jun 28, 2013 at 11:12 AM · c#networkingmultiplayer

How to connect to hosted scene (Multiplayer)

So I have followed some tutorials on youtube on how to connect to a server and also how to set up a server, but now I wanna know how the client that is connecting to the host can go right into a scene that the host is currently hosting kinda.

Anyhow, here's my script (C#):

 using UnityEngine;
 using System.Collections;
 
 public class Network_Menu : MonoBehaviour {
 
 
     public string IP = "127.0.0.1";
     public int Port = 25000;
     
     
     
     void OnGUI()
     {
      if(Network.peerType == NetworkPeerType.Disconnected)
        
         {
             
         if(GUI.Button(new Rect(100,100,100,25),"Start Client"))
             {
             
             Network.Connect(IP,Port);
                 
                 
             }
             
             if(GUI.Button(new Rect(100,125,100,25),"Start Server"))
             {
             
             Network.InitializeServer(4,Port);
                 
                 
             }
             
             
             
             
         }
         
         else {
             if(Network.peerType == NetworkPeerType.Client)
             {
                 
                 GUI.Label(new Rect(100,100,100,25), "Client");
                 
                 if(GUI.Button(new Rect(100,125,100,25), "Logout")){
                 
                     
                     Network.Disconnect(250);
                     
                 }
                     
             }
             
             if(Network.peerType == NetworkPeerType.Server)
             {
                 
                 
                 
                 GUI.Label(new Rect(100,100,100,25), "Client");
                 GUI.Label(new Rect(100,125,100,25), "Connections: " + Network.connections.Length);
                 
                 
                 if(GUI.Button(new Rect(100,150,100,25), "Logout")){
                 
                     
                     Network.Disconnect(250);
                     
                 }
                 
                 
                 
             }
             
         }
         
     }
     
 
     
 }
 
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Ashkan_gc · Jun 28, 2013 at 12:08 PM

In OnPlayerConnected you can send the connected client as a RPC, name of the scene that he/she should load. Then in client in RPC just check if the sender is the server and if yes then load that scene.

Comment
Add comment · Show 4 · 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
avatar image TheRichardGamer · Jun 29, 2013 at 07:39 AM 0
Share

Ok, so I'm going to assume OnPlayerConnected is a function, but what is a RPC? Could you give me an example code?

avatar image DaveA · Jun 29, 2013 at 07:50 AM 1
Share

After you read this and everything it links to, ask again: http://docs.unity3d.com/Documentation/Components/class-NetworkView.html

avatar image TheRichardGamer · Jun 29, 2013 at 09:41 AM 0
Share

I've actually managed the host and the clients to load the scene but they all play individually and not together on the same scene, help please?

avatar image TheRichardGamer · Jul 03, 2013 at 02:31 PM 0
Share

Can you give me a example code?

avatar image
0

Answer by moodiey · Sep 01, 2017 at 02:46 AM

I'm also curious on how to accomplish this.

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

18 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

Related Questions

Unity networking tutorial? 6 Answers

setup a php master server 2 Answers

how to test your multiplayer game 2 Answers

C# How to have a gun select 1 Answer

Unity3D Photon movement synchronization 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