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 BigDakaFa7 · Dec 01, 2013 at 09:38 PM · guinetworking

What can i use besides an event current

Ok so i posted a question the other day asking about why does my built version do things twice and i found why it does but i dont know how to fix it :( So basically when the user types a message and presses enter it sends the message to the server and the chat logs ur name plus ur message, but when u go to type a second message it pops up with the 1st letter you type without pressing enter. All this stuff happens inside OnGui and Update. Heres the code that sends the message

 void OnGUI() 
     {
      
         GUIStyle boxStyle = "box";
         //boxStyle.wordWrap = true; 
         Event e = Event.current;
         if(e.keyCode == KeyCode.Return && !chat){
             chat=true;
             DebugConsole.Log (chat);
             
             DebugConsole.Log ("message sent");
             
         }
 
         stringToEdit = GUI.TextField(new Rect(Screen.width /50f,Screen.height / 1.05f, 300,20),stringToEdit,25);
         
 
         
       scrollView = GUI.BeginScrollView(new Rect(Image.pixelInset.x ,Screen.height - (Image.pixelInset.height / 1.5f) - Image.pixelInset.y * 4f, Image.pixelInset.width ,Image.pixelInset.height / 1.8f), scrollView, new Rect(0,0,100,scroll), new GUIStyle(), GUI.skin.verticalSlider);
       GUI.TextArea(new Rect(0,0,999999,999999),msglist, scroll);
         GUI.EndScrollView();
         
         
         
        if(GUI.Button( new Rect(Image.pixelInset.x + Image.pixelInset.width / 1.1f, Screen_height - Image.pixelInset.y - Image.pixelInset.height + Image.pixelInset.height/ 20, Image.pixelInset.width / 15, Image.pixelInset.height / 10) , "", style) ){
          Debug.Log("Closing Chat");
          gameObject.SetActive(false);
  
        }
     }


heres the code that receives the message and sends it to the server

 void Update () {
         if(chat && stringToEdit != ""){
             
                         //chat = false;
             //speechBubble.text = stringToEdit;
           msglist += "";  
             UdpClient client = new UdpClient (Server.IP, Server.port);
         Packet p = new Packet ((byte)Command.Chat,  stringToEdit + "|" + MapModeLot.currentLot.getID() + "|" + Login_script.publicUsername);
         client.Send (p.ToBytes (), p.ToBytes ().Length);
             stringToEdit = "" ;
             lines ++;    
             DebugConsole.Log ("message received");
             
         }
         
             //DebugConsole.Log (chat);
         
         chat = false;
         
         if(chat)
         {
             scrollView.y = scroll;
         }
                          
 
     }


and here is a picture of the debug console log in gamealt text

Now as u can see the message is sent when u hit enter the first time and its received. Then for some reason it acts like i pressed enter twice when i only pressed it once. Now keep in mind I've tried to use different ways of using the return key and event.current seems to be the only way i can send a message in a Gui.TextArea. If there are any alternate ways of doing this please help me i would much appreciate it.

unity 2013-12-01 13-30-46-29.png (431.4 kB)
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
1
Best Answer

Answer by robertbu · Dec 01, 2013 at 09:49 PM

Not my area of expertise, but maybe you can fix it this way:

 if(e.type == EventType.KeyDown && e.keyCode == KeyCode.Return && !chat){
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 BigDakaFa7 · Dec 01, 2013 at 10:13 PM 0
Share

Dude believe or not that actually worked haha thanks

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

16 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

Related Questions

Need help with my script 0 Answers

What is frame, How OnGuI is called every frame? 2 Answers

How to simplify my Equipment method? 1 Answer

How may I get the children (direct and dependents) of a game object? 2 Answers

RPC instantiate owner problem 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