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 buildman99 · May 31, 2011 at 10:46 AM · c#networkingmultiplayer

Unity3d Csharp Networking Error

I am Making a multiplayer game but the script has a little Error in it.

EDIT I HAVE ADDED SEMICOLON IN BUT THERE IS TWO MORE ERRORS

The Errors are: expected ";" on lines (60,28) , (46,25)

The Code is:

 using UnityEngine;
 using System.Collections;
 using System;
 
 public class MPBase : MonoBehaviour {
 
     public string connectToIp = "127.0.0.1";
     public int connectPort = 25000;
     public bool useNAT = false;
     public string ipaddress = "";
     public string port = "";
     
     string playerName = "InsertNameHere";
     
     void OnGUI()
     {
         if(Network.peerType == NetworkPeerType.Disconnected)
         {
             if (GUILayout.Button("Connect"))
             {
                 if (playerName != "InsertNameHere")
                 {
                     Network.useNat = useNAT;
                     Network.Connect(connectIp, connectport);
                     PlayerPrefs.SetString("playerName", playerName);
                     
                 }
             }
                 if(GUILayout.Button("Start Server"))
                 {
                     if (playerName != "InsertNameHere")
                     {
                         Network.useNat = useNAT;
                         Network.InitializeServer(32, connectPort);
                         
                         foreach (GameObject go in FindObjectsOfType(typeof(GameObject)))
                         {
                             go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
                         }
                         PlayerPrefs.SetString("playerName", playerName);
                     }
                 }
                 
                 playerName = GUILayout.TextField(playerName);
                 connectToIp = GUILayout.TextField(connectToIp)
                 connectPort = Convert.ToInt32(GUILayout.TextField(connectPort.ToString()));
         }
         else
         {
             if(Network.peerType == NetworkPeerType.Connecting) GUILayout.Label("Connect Status: Connecting");
             else if(Network.peerType == NetworkPeerType.Client)
             {
                 GUILayout.Label("Connection Status: Client!");
                 GUILayout.Label("Ping To Server: " + Network.GetAveragePing(Network.connections[0]));
             }
             else if(Network.peerType == NetworkPeerType.Server)
             {
                 GUILayout.Label("Connection Status: Server!");
                 GUILayout.Label("Connections: " + Network.connections.Length);
                 if(Network connections.Length >= 1)
                    GUILayout.Label("Ping to Server: "+ Network.GetAveragePing(Network.connections[0]));
             }
         
             if(GUILayout.Button("Disconnect"))
             Network.Disconnect(200);
             
             ipaddress = Network.player.ipAddress;
             port = Network.player.port.ToString();
             GUILayout.Label("IP Address: " + ipaddress + ":" + port);
         
         }
     }
 
     void OnConnectedToServer
     {
        foreach (GameObject go in FindObjectsOfType(typeof(GameObject)))
                         {
                             go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
                         }
                }
            }
        }


 
 
 
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by pragmascript · May 31, 2011 at 10:51 AM

you forgot a semicolon

public bool useNAT = false;

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
avatar image
0

Answer by homeros · May 31, 2011 at 10:52 AM

public bool useNAT = false is missing a semicolon at the end.

Comment
Add comment · Show 1 · 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 homeros · May 31, 2011 at 01:02 PM 0
Share

you're still missing semicolon at the mentioned line... Seriously, you don't have any idea how to fix a semicolon error and you're trying networking?

avatar image
0

Answer by CHPedersen · May 31, 2011 at 01:40 PM

The line,

connectToIp = GUILayout.TextField(connectToIp)

Is also missing a semi-colon.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Unity networking tutorial? 6 Answers

Multiplayer Problems 1 Answer

Client can't spawn GameObject's 0 Answers

[Command] Attribute Returning Warnings and Errors 0 Answers

SyncVar issue 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