Make A Chat

Hello, I made a script that makes my GUI.Window. How do I add a chat to the GUI.Window. If anyone could help me add the chat to this script it would be great.

/* GUI.Toolbar example */

var newSkin : GUISkin;
var myBoolean = false;
private var windowRect : Rect = Rect (5,365,480, 200);

function OnGUI () 
{
	GUI.skin = newSkin;
	if(GUI.Button(Rect(85,565,80,30), "Chat"))
	{
		if(myBoolean == false)
			myBoolean = true;
	}
	
	if(myBoolean)
		windowRect = GUI.Window (0, windowRect, DoMyWindow, "World Chat");
}
	
function DoMyWindow (windowID : int) 
{
	if(GUI.Button (Rect (450,3,25,25), "X")){
	myBoolean = false;
	}
}

Thankyou
Chris

Well theres a few questions i should ask first, one is quite plain, is this over the unity network (like from the Unity Networking Example) or over a Server (like beam server and php scriptping?). Or possibly is this just on a single user screen?

No matter what its over if you want i can send you my script for my chat window, its not the best but it works. Its only for one person, but can probably be easily adapted to a multiplayer scene.

Yes, that would be great thankyou.

To make the script work you need two scripts, the fist is this

var GlobalChat;
var TextTyping: String= "";
var Name:String="Adam";
function Start(){
GlobalChat=GameObject.Find("GlobalChat").GetComponent("ArrayChatTest");
}
function OnGUI () {
TextTyping = GUI.TextField (Rect (10, Screen.height-22, 500, 22), TextTyping,90);


}

function Update(){
if(Input.GetKeyDown(KeyCode.Return)){
if(TextTyping!=""){
GlobalChat.AddLineToChat(Name,TextTyping);
TextTyping="";
}
}
}

attach this next script to an object in your scene called GlobalChat

private var SaidStuff=new Array();
private var scrollPosition : Vector2 = Vector2.zero;
function Start(){
AddLineToChat("","Welcome to my chat test!");
AddLineToChat("","type /Help for some basic commands");
}
function OnGUI () {
var ViewPort=(25*(SaidStuff.length-4));
if(ViewPort<0){
	ViewPort=0;
}

scrollPosition = GUI.BeginScrollView (Rect (10,Screen.height-150,420,100),scrollPosition, Rect (0, 0, 400,100+ViewPort),false,true);
var HeightOfBox=(25*(SaidStuff.length-4));
if(HeightOfBox<0){
HeightOfBox=0;
}
GUI.Box(Rect(0,0,400,100+HeightOfBox)," ");
for(var i : int  =0; i<SaidStuff.length; i++){
	GUI.Label(Rect(0,(25*i),400,23),SaidStuff[i]);
}
GUI.EndScrollView();
}




function AddLineToChat(Name:String,Text : String){

SaidStuff.Push(Text);
if(Text=="/Help"){
DisplayHelp();
}
if(Text=="/Top"){
scrollPosition=Vector2.zero;
} else{
var LowestSpot:Vector2=Vector2(0,25*(SaidStuff.length-4));
if(LowestSpot.y<0){
LowestSpot.y=0;
}
scrollPosition=LowestSpot;
}
if(Text=="/Clear"){
SaidStuff.length=0;
AddLineToChat("","Cleared chat");
}
}


function DisplayHelp(){
AddLineToChat("","  ");
AddLineToChat("","Here are some commands!");
AddLineToChat("","/Clear to clear your chat history");
AddLineToChat("","/Top to go back to the top");
}

put these into your game and you should be golden

Thankyou mate, I used to know the leader of omuni online. however I had to make room on my skype so I deleted him.

Thankyou
Chris

Offtopic : Skype doesn’t have a limit to how many contacts you could have…

I know, I was just deleting everyone who was not in the team i’m working with.

Help me pls
1 script error :Chat.js(16,12): BCE0019: ‘AddLineToChat’ is not a member of ‘Object’.

var GlobalChat;
var TextTyping: String= "";
var Name:String="Adam";
function Start(){
GlobalChat=GameObject.Find("GlobalChat").GetComponent("ArrayChatTest");
}
function OnGUI () {
TextTyping = GUI.TextField (Rect (10, Screen.height-22, 500, 22), TextTyping,90);
}
function Update(){
if(Input.GetKeyDown(KeyCode.Return)){
if(TextTyping!=""){
GlobalChat.AddLineToChat(Name,TextTyping);
TextTyping="";
}
}
}

and 2 script error :
Test.js(20,14): BCE0004: Ambiguous reference ‘Label’: UnityEngine.GUI.Label(UnityEngine.Rect, UnityEngine.GUIContent), UnityEngine.GUI.Label(UnityEngine.Rect, UnityEngine.Texture), UnityEngine.GUI.Label(UnityEngine.Rect, String).

private var SaidStuff=new Array();
private var scrollPosition : Vector2 = Vector2.zero;
function Start(){
AddLineToChat("","Welcome to my chat test!");
AddLineToChat("","type /Help for some basic commands");
}
function OnGUI () {
var ViewPort=(25*(SaidStuff.length-4));
if(ViewPort<0){
    ViewPort=0;
}
scrollPosition = GUI.BeginScrollView (Rect (10,Screen.height-150,420,100),scrollPosition, Rect (0, 0, 400,100+ViewPort),false,true);
var HeightOfBox=(25*(SaidStuff.length-4));
if(HeightOfBox<0){
HeightOfBox=0;
}
GUI.Box(Rect(0,0,400,100+HeightOfBox)," ");
for(var i : int  =0; i<SaidStuff.length; i++){
    GUI.Label(Rect(0,(25*i),400,23),SaidStuff[i]);
}
GUI.EndScrollView();
}
function AddLineToChat(Name:String,Text : String){
SaidStuff.Push(Text);
if(Text=="/Help"){
DisplayHelp();
}
if(Text=="/Top"){
scrollPosition=Vector2.zero;
} else{
var LowestSpot:Vector2=Vector2(0,25*(SaidStuff.length-4));
if(LowestSpot.y<0){
LowestSpot.y=0;
}
scrollPosition=LowestSpot;
}
if(Text=="/Clear"){
SaidStuff.length=0;
AddLineToChat("","Cleared chat");
}
}
function DisplayHelp(){
AddLineToChat("","  ");
AddLineToChat("","Here are some commands!");
AddLineToChat("","/Clear to clear your chat history");
AddLineToChat("","/Top to go back to the top");
}