Hi, now I’m currently working on chat window,
and I managed to find following code that implements chat window:
public var commandLine:String = "";
function OnGUI () {
if (Event.current.Equals (Event.KeyboardEvent ("return")) )
{
print("return pressed");
isTalking = !isTalking;
}
if(isTalking){
GUI.SetNextControlName ("ChatField");
commandLine = GUI.TextField (Rect (10, 80, 600, 20), commandLine, 25);
GUI.FocusControl ("ChatField");
}
if (commandLine!="" isTalking == false)
{
// What now?!
}
}
This is typical wow style chat window, where if you press enter, chat window appears, and press it again to make it disappear.
But thing it passes message typed to nowhere!
I’m pretty sure i have to do something in //What now?! part, but since it’s OnGUI() function so if I try to call any function that displays variable “commandLine”, it prints that out every frame, not just once.
Also, I want to make some kind of chat history, so it displays up to last 10 lines that user typed. May be I have to use some arrays, but I’m so noob.
it will only print it once actually if you reset commandLine to “” after sending it, which you are likely wanting to do as you want to send it to the server there and to the chat history
Thanks, I kinda managed to change all of these global thingy to local variables - so that’s fine - Thanks for updating the script tho. (Now I can compare so to check whether I’ve done it correctly!)
By the way - as you know the purpose of the chat is to chat online - right? is there any additional script or tweaks to make it kinda multiplayer?
It is already multiplayer! You just have to add a networkview to the gameobject which contains this script.
Ah and a AudioSource, because i am playing a sound everytime a new chatline appears
Oh! I see. So that’s was the part that does network thingy! You are awesome!
I think I saw that kind of Network view and RPC thingy somewhere… among the hundreds of tutorials I have :S
Still, may be I have to study networking lot more… since I don’t know what to do next
(I KNOW NOTHING ABOUT NETWORKING - and the most of scripting I do not know either (what do I know?!))
I think it’s too hard for me to turn my little game into multiplayer game! T-T
btw, uncommenting RPC part, it gives me error like this: