- Home /
chat on collision c#
Can anyone guide me in the direction of a script that prompts the user in a chat dialogue once they collide with the object. I know its possible but i cant get mine too work
Answer by $$anonymous$$ · May 04, 2014 at 01:33 PM
For example like this:
ArrayList Chat = new ArrayList();
void OnCollisionEnter(Collision collision)
{
Chat.add("You hit "+collision.collider.name);
}
void OnGUI()
{
int i = 1;
int top = 110;
int height = 100;
foreach(string S in Chat)
{
Rect TextRect = new Rect(10,i*top,Screen.width-10,height);
GUI.Label(TextRect,S);
i++;
}
}
I think i understand this better now thanks. but what exactly is the array used for and three ints ?
the ArrayList contains the strings of the chat.
int i is just to count the strings of the ArrayList.
int top is the margin on the top: for example there are 3 strings in your chat => - yLocation of string 1 = 1*top(110) = 110 - yLocation of string 2 = 2*top(110) = 220 - yLocation of string 3 = 3*top(110) = 330 - ...
-int height is just a arbitrarily variable of the labels height.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Name/Screen Name Input 0 Answers
How to have both, a scroll view AND vertical Layout? 1 Answer
How can i create a conversion like whatsapp in unity3d 0 Answers