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 Lewenos 1 · May 02, 2011 at 01:53 PM · typechatfun

ChatBox InGame With Slider

Hi. Im making game where players can talk in chatbox. It needs to be something like in runescape. [Player Name] : "Your Text" and when i press enter, it sends my text, and it will be showing like 3 seconds above my player. Then when i hit enter, text will appear to chatbox and my name is first, like: [PlayerName]: "MyText".

And Chatbox needs to have lines, when there comes more text, you can slide and read them on chatbox. And ofcourse when i hit enter, text appears to chatbox and disappears from writing box.

__________________________________________
|                                       | |
|                                       | |
|                                       | |   <----- Slider
|                                       | |
|Admin: hows going?                     | |
|Lew: hi everyone                       | |   <----- Here comes name and text.
|-----------------------------------------|
|Lew: "Here comes text"                   |   <----- Player name and his text
------------------------------------------ 

Thanks for help in advance!

Comment
Add comment · Show 1
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 Razial7 · Jan 11, 2013 at 02:43 AM 0
Share

did you ever figure this out trying to do this as well I have everything but cant figure out why it wont print what i enter

3 Replies

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

Answer by Yokimato · Mar 25, 2013 at 08:58 PM

Here's a javascript solution:

 /* 
 
 *  This file is part of the Unity networking tutorial by M2H ([url]http://www.M2H.nl[/url])
 
 *  The original author of this code is Mike Hergaarden, even though some small parts 
 
 *  are copied from the Unity tutorials/manuals.
 
 *  Feel free to use this code for your own projects, drop us a line if you made something exciting! 
 
 */
 
 #pragma strict
 
  
 
  
 
 public static var usingChat : boolean = false;  //Can be used to determine if we need to stop player movement since we're chatting
 
 var skin : GUISkin;                     //Skin
 
 static var showChat : boolean= false;           //Show/Hide the chat
 
  
 
 //Private vars used by the script
 
 private var inputField : String= "";
 
  
 
 private var scrollPosition : Vector2;
 
 private var width : int= 190;
 
 private var height : int= 180;
 
 private var playerName : String;
 
 private var lastUnfocus : float =0;
 
 private var window : Rect;
 
 private var lastEntry : float = 0.0;
 
 private var netView : NetworkView;
 
 private static var thisScript : FPSChat;
 
     
 
 private var chatEntries = new ArrayList();
 
 class FPSChatEntry
 
 {
 
     var name : String= "";
 
     var text : String= "";  
 
 }
 
  
 
  
 
 function Awake(){
 
     usingChat=false;
 
     
 
     netView = networkView;
 
     thisScript = this;
 
     
 
     window = Rect(Screen.width-185, 20 + scoreBoard.scoreBoardHeight, width, height);
 
     lastEntry = Time.time;
 
     
 
     playerName = PlayerPrefs.GetString("playerName", "");
 
     if(!playerName || playerName==""){
 
         playerName = "RandomName"+Random.Range(1,999);
 
     }   
 
 }
 
  
 
 function CloseChatWindow ()
 
 {
 
     showChat = false;
 
     inputField = "";
 
     chatEntries = new ArrayList();
 
 }
 
  
 
 function ShowChatWindow ()
 
 {
 
     showChat = true;
 
     inputField = "";
 
     chatEntries = new ArrayList();
 
 }
 
  
 
 function OnGUI ()
 
 {
 
     if(!showChat){
 
         return;
 
     }
 
     
 
     if (PlayerInfos.ScreenState() && PlayerInfos.IsUsingStore()){
 
         return;
 
     }
 
     
 
     GUI.skin = skin;
 
     
 
     window.y = 20 + scoreBoard.scoreBoardHeight;
 
             
 
     if (Event.current.type == EventType.keyDown && Event.current.character == "\n" && inputField.Length <= 0)
 
     {
 
         if(lastUnfocus+0.25<Time.time){
 
             usingChat=true;
 
             GUI.FocusWindow(5);
 
             GUI.FocusControl("Chat input field");
 
             Screen.lockCursor = false;
 
         }
 
     }
 
     if (Time.time - lastEntry > 10 && Network.isServer){
 
         addGameChatMessage(" ");
 
         lastEntry = Time.time;
 
     }
 
  
 
     //Screen.lockCursor = screenLock;
 
     window = GUI.Window (5, window, GlobalChatWindow, "");
 
 }
 
  
 
  
 
 function GlobalChatWindow (id : int) {
 
     
 
     GUILayout.BeginVertical();
 
     GUILayout.Space(10);
 
     GUILayout.EndVertical();
 
     
 
     // 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 : FPSChatEntry in chatEntries)
 
     {
 
         GUILayout.BeginHorizontal();
 
         if(entry.name==""){//Game message
 
             GUILayout.Label (entry.text);
 
         }else{
 
             GUILayout.Label (entry.name+": "+entry.text);
 
         }
 
         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)
 
     {
 
         HitEnter(inputField);
 
     }
 
     else if (Event.current.type == EventType.keyDown && Event.current.character == "\n" && inputField.Length == 0){
 
         inputField = ""; //Clear line
 
         GUI.UnfocusWindow ();//Deselect chat
 
         lastUnfocus=Time.time;
 
         usingChat=false;
 
         Screen.lockCursor = true;
 
     }
 
     GUI.SetNextControlName("Chat input field");
 
     inputField = GUILayout.TextField(inputField);
 
     
 
     
 
     if(Input.GetKeyDown("mouse 0")){
 
         if(usingChat){
 
             usingChat=false;
 
             GUI.UnfocusWindow ();//Deselect chat
 
             lastUnfocus=Time.time;
 
         }
 
     }
 
     //if (Screen.lockCursor == false){
 
         //if(usingChat){
 
             //usingChat=false;
 
             //GUI.UnfocusWindow ();//Deselect chat
 
             //lastUnfocus=Time.time;
 
         //}
 
     //}
 
 }
 
  
 
 function HitEnter(msg : String){
 
     msg = msg.Replace("\n", "");
 
     netView.RPC("ApplyGlobalChatText", RPCMode.All, playerName, msg);
 
     inputField = ""; //Clear line
 
     GUI.UnfocusWindow ();//Deselect chat
 
     lastUnfocus=Time.time;
 
     usingChat=false;
 
     Screen.lockCursor = true;
 
 }
 
  
 
 static function StaticMsg(msg : String){
 
     thisScript.HitEnter(msg);
 
 }
 
  
 
  
 
 @RPC
 
 function ApplyGlobalChatText (name : String, msg : String)
 
 {
 
     var entry : FPSChatEntry = new FPSChatEntry();
 
     entry.name = name;
 
     entry.text = msg;
 
  
 
     chatEntries.Add(entry);
 
     lastEntry = Time.time;
 
     
 
     //Remove old entries
 
     if (chatEntries.Count > 4){
 
         chatEntries.RemoveAt(0);
 
     }
 
  
 
     scrollPosition.y = 1000000; 
 
 }
 
  
 
 //Add game messages etc
 
 function addGameChatMessage(str : String){
 
     ApplyGlobalChatText("", str);
 
     if(Network.connections.length>0){
 
         networkView.RPC("ApplyGlobalChatText", RPCMode.Others, "", str);    
 
     }   
 
 }
Comment
Add comment · 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
-1

Answer by GesterX · May 02, 2011 at 02:15 PM

There is a nice tutorial to do something extremely similar in the M2H Networking tutorial available from the Asset Store. More detials here:

http://forum.unity3d.com/threads/75385-Ultimate-Unity-Networking-project-Add-multiplayer-to-your-game-today!

It costs a small price but is ultimately worth it since it teaches you what you need to know to add multiplayer/chat/networking to any game.

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 Lewenos 1 · May 02, 2011 at 06:25 PM 0
Share

Uh and Ah.. Costs too much.. But thanks anyway

avatar image Yokimato · Mar 25, 2013 at 08:56 PM 1
Share

I don't feel this is very helpful; it doesn't point to an answer and what it does point to, is a very expensive solution, of which contains way more then what the questions was about.

avatar image
0

Answer by Pommimonni · May 26, 2014 at 02:40 PM

Some answers here http://forum.unity3d.com/threads/58791-I-m-making-a-GUI-Chatbox-for-all!-(Please-help-lol)

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Chat script in Networking 1 Answer

Variable type Target Unity 3 Answers

Pray Style Sticky Walkways 1 Answer

Unity and Facebook chat? 1 Answer

How to prevent ignored input after typing in a GUI? 0 Answers


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