Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Can you Help me With 2 Error in one Script? C#

Discussion in 'Editor & General Support' started by EdgarCarrera, Jun 12, 2014.

  1. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    Assets/Scripts/MPBase.cs(22,49): error CS0117: `UnityEngine.Network' does not contain a definition for `useNAT'

    Assets/Scripts/MPBase.cs(32,49): error CS0117: `UnityEngine.Network' does not contain a definition for `useNAT'

    Assets/Scripts/MPBase.cs(45,39): error CS0103: The name `Convert' does not exist in the current context

    Full Script
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class MPBase : MonoBehaviour {
    5.  
    6.     public string connectToIp = "127.0.0.1";
    7.     public int connectPort = 25000;
    8.     public bool useNAT = false;
    9.     public string ipaddress = "";
    10.     public string port = "";
    11.  
    12.     string playerName = "Player Name";
    13.  
    14.     void OnGUI(){
    15.  
    16.         if(Network.peerType == NetworkPeerType.Disconnected)
    17.         {
    18.             if(GUILayout.Button("Connect"))
    19.             {
    20.                 if(playerName != "Player Name")
    21.                 {
    22.                     Network.useNAT = useNAT;
    23.                     Network.Connect(connectToIp, connectPort);
    24.                     PlayerPrefs.SetString("playerName", playerName);
    25.                 }
    26.             }
    27.  
    28.             if(GUILayout.Button("Start Server"))
    29.             {
    30.                 if(playerName != "Player Name")
    31.                 {
    32.                     Network.useNAT = useNAT;
    33.                     Network.InitializeServer(32,connectPort);
    34.  
    35.                     foreach(GameObject go in FindObjectsOfType(typeof(GameObject)))
    36.                     {
    37.                         go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
    38.                     }
    39.                     PlayerPrefs.SetString("playerName", playerName);
    40.                 }
    41.             }
    42.  
    43.             playerName = GUILayout.TextField(playerName);
    44.             connectToIp = GUILayout.TextField(connectToIp);
    45.             connectPort = Convert.ToInt32(GUILayout.TextField(connectPort, ToString()));
    46.  
    47.         } else {
    48.             if(Network.peerType == NetworkPeerType.Connecting) GUILayout.Label("Connect Status: Connecting");
    49.             else if(Network.peerType == NetworkPeerType.Client)
    50.             {
    51.                 GUILayout.Label("Connection Status: Client!");
    52.                 GUILayout.Label("Ping to Server: " + Network.GetAveragePing(Network.connections[0]));
    53.             }
    54.             else if (Network.peerType == NetworkPeerType.Server)
    55.             {
    56.                 GUILayout.Label("Connection Status: Server!");
    57.                 GUILayout.Label("Connections: " + Network.connections.Length);
    58.                 if(Network.connections.Length >= 1)
    59.                     GUILayout.Label("Ping to Server: " + Network.GetAveragePing(Network.connections[0]));
    60.             }
    61.  
    62.             if(GUILayout.Button("Disconnect"))
    63.                 Network.Disconnect(200);
    64.  
    65.             ipaddress = Network.player.ipAddress;
    66.             port = Network.player.ToString();
    67.             GUILayout.Label("IP Address: " + ipaddress + ":" + port);
    68.         }
    69.     }
    70.     void OnConnectedToServer()
    71.     {
    72.         foreach(GameObject go in FindObjectsOfType(typeof(GameObject)))
    73.         {
    74.             go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
    75.         }
    76.     }
    77. }
    78.  
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    They're pretty self-explanatory. There's no member or variable in the Network class called "useNAT"; why have you used it? Or did this code come from somewhere else?

    Similarly, there's no function called "Convert" in the script. It means exactly what it says.
     
  3. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    Google for "C# namespces" and then "Convert.ToInt32."

    Also see the last paragraph in this post.
     
  4. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    This Video:


    im Testing this code.
     
  5. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    i'm testing System.Convert.ToInt32 and got more errors.
     
  6. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    If you really want to learn then you should try to solve the problem yourself. You're not going to learn much if you're just going to type what you see and then come running to the forum when you make a typo or miss a line.

    No, you're not testing it. You're just using it wrong.
     
  7. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    Can you help me? i'm new here.
     
  8. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    Alreayd fixed :D
    connectPort = System.Convert.ToInt32(GUILayout.TextField(connectPort.ToString()));
     
  9. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    Assets/Scripts/MPBase.cs(22,49): error CS0117: `UnityEngine.Network' does not contain a definition for `useNAT'
     
  10. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    the other solution useNAT to useNat