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
0
Question by centilmen50 · Feb 05, 2014 at 12:05 AM · scriptingproblem

Pressing the enter key to chat script writing TextField How can I activate?

Pressing enter my chat script to write TextField How can I activate?

DontDestroyOnLoad(this);

 var          mySkin : GUISkin;
 private var     gameNameType = "UnityChat"; // leave this alone. then we will see all other builds of this example
 var          myGameName : String = "thylaxene's Chat";
 var          gameDesc : String = "Very Basic Chat App";
 var          userName : String;
 private var     timeoutHostList = 0.0;
 private var     lastHostListRequest = -1000.0;
 private var     hostListRefreshTimeout = 10.0;
  
 public var      serverPort = 25002;
 private var     natCapable : ConnectionTesterStatus;
 private var     filterNATHosts = false;
 private var     doneProbingPublicIP = false;
 private var     hideTest = true;
  
 private var     windowRect = Rect (-110,40,100,50);
 private var     windowRectT = Rect (100,290,200,300);
 var          scrollViewVector : Vector2;
  
 private var     outputText : String = "";
 private var     yourInputText : String = "";
  
 // Enable this if not running a client on the server machine
 //MasterServer.dedicatedServer = true;
  
 function OnFailedToConnectToMasterServer(info: NetworkConnectionError) {
     Debug.Log(info);
 }
  
 function OnFailedToConnect(info: NetworkConnectionError) {
     Debug.Log(info);
 }
  
 function OnDisconnectedFromServer (info: NetworkDisconnection) {
     Debug.Log(info);
 }
  
 function OnServerInitialized () {
     networkView.RPC ("SendMessage", RPCMode.AllBuffered,  (userName + " Baglandi"));
 }
  
 function OnConnectedToServer () {
     networkView.RPC ("SendMessage", RPCMode.All,  (userName + " Baglandi"));
 }
  
 function OnGUI () {
     GUI.skin = mySkin;
     windowRect = GUILayout.Window (0, windowRect, MakeWindow, "Giris Kontrolu");
     windowRectT = GUILayout.Window (1, windowRectT, MakeTranscriptWindow, "Chat Alani");
 }
  
 function Awake () {
     // Start connection test
     natCapable = Network.TestConnection();
  
     // What kind of IP does this machine have? TestConnection also indicates this in the
     // test results
     if (Network.HavePublicAddress())
        Debug.Log("This machine has a public IP address");
     else
        Debug.Log("This machine has a private IP address");
 }
  
 function MakeTranscriptWindow () {
     GUILayout.Label ("Mesajlar:");
     scrollViewVector = GUILayout.BeginScrollView (scrollViewVector);
        GUILayout.TextArea (outputText);
     GUILayout.EndScrollView();
     GUILayout.Label("Mesajin: "); 
     yourInputText = GUILayout.TextField (yourInputText);
     if (GUILayout.Button ("Gonder")) {
        networkView.RPC ("SendMessage", RPCMode.All,  yourInputText);
        yourInputText = "";
     }
  
     GUI.DragWindow (Rect (0,0,1000,1000));
 }
  
 // this is where the magic is. when this function is called via networkView.RPC
 // everyone's chat log is updated
 @RPC
 function SendMessage (text : String) { 
     outputText += (text + "\n"); 
 }
  
 function Update() {
     if(Input.GetKeyDown(KeyCode.Escape))
      mert = !SendMessage;
  
     if(Input.GetKeyDown(KeyCode.Return))
    networkView.RPC ("SendMessage", RPCMode.All,  yourInputText);
  
 }
  
 function MakeWindow (id : int) {
     GUILayout.BeginHorizontal ();
        GUILayout.Label ("Adiniz:");
        userName = GUILayout.TextField (userName);
     GUILayout.EndHorizontal ();
  
     hideTest = GUILayout.Toggle(hideTest, "Ellesme");
  
     if (!hideTest) {
        // Start/Poll the connection test, report the results in a label and react to the results accordingly
        natCapable = Network.TestConnection();
        if (natCapable == -2)
          GUILayout.Label("Problem determining NAT capabilities");
        else if (natCapable == -1)
          GUILayout.Label("Undetermined NAT capabilities");
        else if (natCapable == 0) {
          GUILayout.Label("Cannot do NAT punchthrough, filtering NAT enabled hosts for client connections, impossible to run a server.");
          filterNATHosts = true;
          Network.useNat = false;
        }
        else if (natCapable == 1) {
          if (doneProbingPublicIP)
           GUILayout.Label("Non-connectable public IP address (port "+ serverPort +" blocked), NAT punchthrough can circumvent the firewall.");
          else
           GUILayout.Label("NAT punchthrough capable. Enabling NAT punchthrough functionality.");
  
          // NAT functionality is enabled in case a server is started, clients enable this based on if the host requires it
          Network.useNat = true;
        } else if (natCapable == 2) {
          GUILayout.Label("Directly connectable public IP address.");
          Network.useNat = false;
        } else if (natCapable == 3) {
          GUILayout.Label("Non-connectble public IP address (port " + serverPort +" blocked), running a server is impossible.");
          Network.useNat = false;
          if (!doneProbingPublicIP) {
           natCapable = Network.TestConnectionNAT();
           doneProbingPublicIP = true;
          }
        }
        else if (natCapable == 4) {
          GUILayout.Label("Public IP address but server not initialized, it must be started to check server accessibility.");
          Network.useNat = false;
        }
  
        if (GUILayout.Button ("Retest connection")) {
          Debug.Log("Redoing connection test");
          doneProbingPublicIP = false;
          natCapable = Network.TestConnection(true);
        }
     }
  
     if (Network.peerType == NetworkPeerType.Disconnected) {
        GUILayout.BeginHorizontal();
        GUILayout.Space(10);
        // Start a new server
        if (GUILayout.Button ("Chat'e Baglan")) {
          Network.InitializeServer(32, serverPort);
          MasterServer.RegisterHost(gameNameType, myGameName, gameDesc);
        }
  
        // Refresh hosts
  
  
        GUILayout.FlexibleSpace();
  
        GUILayout.EndHorizontal();
  
        GUILayout.Space(5);
  
        var data : HostData[] = MasterServer.PollHostList();
        for (var element in data) {
          GUILayout.BeginHorizontal();
  
          // Do not display NAT enabled games if we cannot do NAT punchthrough
          if ( !(filterNATHosts && element.useNat) ) {
           var name = element.gameName + " " + element.connectedPlayers + " / " + element.playerLimit;
           GUILayout.Label(name);  
           GUILayout.Space(5);
           var hostInfo;
           hostInfo = "[";
           for (var host in element.ip) {
               hostInfo = hostInfo + host + ":" + element.port + " ";
           }
           hostInfo = hostInfo + "]";
           //GUILayout.Label("[" + element.ip + ":" + element.port + "]"); 
           GUILayout.Label(hostInfo);  
           GUILayout.Space(5);
           GUILayout.Label(element.comment);
           GUILayout.Space(5);
           GUILayout.FlexibleSpace();
           if (GUILayout.Button("Giris Yap")) {
               // Enable NAT functionality based on what the hosts if configured to do
               Network.useNat = element.useNat;
               if (Network.useNat)
                  print("Using Nat punchthrough to connect");
               else
                  print("Connecting directly to host");
               Network.Connect(element.ip, element.port);        
           }
          }
          GUILayout.EndHorizontal();   
        }
     } else {
  
        GUILayout.FlexibleSpace();
     }
     GUI.DragWindow (Rect (0,0,1000,1000));
 }
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

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

Multiple Cars not working 1 Answer

Raycast Destroys player. 1 Answer

GUI cale and position according to the actual screen resolution. 1 Answer

GUI.HorizontalSlider not working 2 Answers

How To Make GUI Buttons Load/Quit 1 Answer


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