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 game[18765-unity+2013-12-01+13-30-46-29.png|18765]
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.
Dude believe or not that actually worked haha thanks
– BigDakaFa7