Java Scrip : ChatWindow

interaction is a nice thing in a game. where users can define their own without keinginya be set primarily by the engine. thus what a computer can interact with it. ate than that required an excellent data scipt for it.

then of the friends I was with friends trying to make it the basis of multimedia interactions using java script unity which has kompenen well in the interaction and use 3d models are now again on the rise.



you might want to try ... and if there is a problem for you please contact us immediately (on Samuelliputra@gmail.com) so that we can improve and make a new one ... good luck




var stringArray : String[]; // The array of strings for the chat window
var writeString : String; // The string the user is currently writing
var maxLines : int = 20; // The maximum number of lines on screen at one time
var curLine : int = 0; // The current top line
var tempLine : float = 0; // The float version of the current top line
var windowRect : Rect; // The rectangle for the window
var myStyle : GUIStyle; // The style for the window text
function Start() // This function runs once on object creation
{
windowRect = Rect(Screen.width * .5 - 300, Screen.height * .5 - 205, 600, 410); // Set the window Rect based on the screen width and height
}
function Update() // This function runs once per frame
{
if (writeString.length > 0 && Input.GetKey(KeyCode.Return)) { // If the temp string has something in it and the user presses return
var tempArray : String[] = new String[stringArray.length + 1]; // Create a temp holder string array
var temp : int = 0; // Set a temp variable to hold the while loop position
while (temp < stringArray.length) { // While the position hasn't reached the end of the string array
tempArray[temp] = stringArray[temp]; // Assign the current string to the temp holder
temp += 1; // Increase position by one
}
tempArray[tempArray.length - 1] = writeString; // Place the new item on the last slot
writeString = ""; // Reset the temp string
stringArray = tempArray; // Set the main holder to the temp
}
}
function OnGUI() // This function runs multiple times per frame and handles GUI code
{
GUI.Box(Rect(Screen.width * .5 - 350, Screen.height * .5 - 255, 700, 510), "Chat Screen"); // Create a box around the chat window
GUI.Window(2, windowRect, ChatWindow, ""); // Create the chat window
writeString = GUI.TextField(Rect(Screen.width * .5 - 300, Screen.height * .5 + 220, 600, 25), writeString, 50); // Set the temp string to the text field's return variable
if (stringArray.length > 20) { // If the array holds more than 20 pieces
tempLine = GUI.VerticalScrollbar(Rect(Screen.width * .5 + 380, Screen.height * .5 - 205, 25, 410), tempLine, 1, 0, stringArray.length - 19); // Set the float to the position from the scrollbar
curLine = tempLine; // Set the integer for the current line to the float (truncated)
}
}
function ChatWindow(windowID : int) // This function holds the contents of the chat window
{
var temp : int = 0; // Create a temp variable for the position in the while loop
while (temp < maxLines && temp + curLine < stringArray.length) { // While the current position is fewer than the max lines and fewer than the length of the string array
GUI.Label(Rect(5,5 + temp * 20, windowRect.width - 10, 20), stringArray[temp + curLine], myStyle); // Print the current line
temp += 1; // Increase the current line position by one
}
}

Tidak ada komentar:

Posting Komentar