Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Antonios · Nov 10, 2010 at 03:58 PM · guinetworkchat

Ingame Chat script

Hi, I found this script in one of unity demo projects...

GUI.FocusControl("Chat input field"); }

function OnGUI () { GUI.skin = skin;

 //if (GUILayout.Button(showChat ? "Hide Chat" : "Display Chat"))
 if (GUI.Button(new Rect(Screen.width-100, Screen.height-30, 90, 20), showChat ? "Hide Chat" : "Display Chat"))
 {
     // Focus first element
     if (showChat)
     {   
         CloseChatWindow ();
     }
     else
     {
         showChat = true;
         FocusControl();
     }
 }

 if (showChat)
     window = GUI.Window (1, window, GlobalChatWindow, "Chat");

}

function GlobalChatWindow (id : int) {

 var closeButtonStyle = GUI.skin.GetStyle("close_button");
 if (GUI.Button(Rect (4, 4, closeButtonStyle.normal.background.width, closeButtonStyle.normal.background.height), "", "close_button"))
 {
     CloseChatWindow();
 }

 // Begin a scroll view. All rects are calculated automatically - 
 // it will use up any available screen space and make sure contents flow correctly.
 // This is kept small with the last two parameters to force scrollbars to appear.
 scrollPosition = GUILayout.BeginScrollView (scrollPosition);

 for (var entry : ChatEntry in entries)
 {
     GUILayout.BeginHorizontal();
     if (!entry.mine)
     {
         GUILayout.FlexibleSpace ();
         GUILayout.Label (entry.text, "chat_rightaligned");
     }
     else
     {
         GUILayout.Label (entry.text, "chat_leftaligned");
         GUILayout.FlexibleSpace ();
     }

     GUILayout.EndHorizontal();
     GUILayout.Space(3);

 }
 // End the scrollview we began above.
 GUILayout.EndScrollView ();

 if (Event.current.type == EventType.keyDown && Event.current.character == "\n" && inputField.Length > 0)
 {
     //@TODO: This should be dependent on who actually sent the message
     //var mine = entries.Count % 2 == 0;
     ApplyGlobalChatText(inputField, 1);
     networkView.RPC("ApplyGlobalChatText", RPCMode.Others, inputField, 0);
     inputField = "";
 }
 GUI.SetNextControlName("Chat input field");
 inputField = GUILayout.TextField(inputField);

 GUI.DragWindow();

}

@RPC function ApplyGlobalChatText (str : String, mine : int) { var entry = new ChatEntry(); entry.sender = "Not implemented"; entry.text = str; if (mine == 1) entry.mine = true; else entry.mine = false;

 entries.Add(entry);

 if (entries.Count > 50)
     entries.RemoveAt(0);

 scrollPosition.y = 1000000; 

}

Don't know how to use it or apply it yet... Can someone please help?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Tarun · Nov 10, 2010 at 10:02 PM

I believe you are talking about the Chat folder in Networking.zip that's out there in http://unity3d.com/support/resources/example-projects/networking-example

This folder comes with a demo scene called "test". If you open that, it'll tell you how this chat script is used. Essentially, you need an empty gameobject with this script added and with NetworkView. Create another empty gameobject with ConnectGUI script for initiating server/client. And you are good to go with a chat scene (using Unity's in-built networking; I'm assuming you've a PRO or 30 day license.)

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Antonios · Nov 11, 2010 at 04:06 PM 0
Share

I did the same as the demo, except that the demo has the window with the typing form... I don't! I replaced all missing components and stuff but I don't have the type box to type in!

avatar image jorgon · Oct 20, 2011 at 09:52 AM 0
Share

When I do that, why appears to me the message:"$$anonymous$$issingReferenceException: The object of type 'Texture2D' has been destroyed but you are still trying to access it.". It is supposed that the Texture2D is being taken from the GUIStyle, isn't it?. I suppose that the code lacks of something or needs something more...

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

BeginScrollView question on auto increasing 1 Answer

Unity freezes when changing GUI.Color.a 1 Answer

Re Enable C# script on camera 1 Answer

Create GUI button in update function? 3 Answers

Quick help on a gui script. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges