• 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
Question by Deepschalappatta · Feb 14, 2014 at 01:15 PM · c#smartfox

Chat window not displayed

Hi, when i am trying to click a chat button, chatwindow(function DrawLobbyGUI())is not displayed properly. But with out chat button it's working fine.....please help

      void OnGUI() {
     if (!started) return;

   GUI.skin = gSkin;
   ShowChatGUI();
     //DrawLobbyGUI();        
 }
 
 
 public void ShowChatGUI(){
     
     
     if (GUILayout.Button("chat"))
     {
         DrawLobbyGUI();
        //Debug.Log("HAI");
     
     }
     }
    public void DrawLobbyGUI() {
     Room currentActiveRoom = smartFox.LastJoinedRoom;
     if ( currentActiveRoom == null ) {
         
         // Wait until active room has been set up in the API before drawing anything
         return;
     }
     //Debug.Log("lobby");
     float chatPanelWidth = Screen.width*1/4;
     float chatPanelHeight = Screen.height/2+20;
     ......................................
     float userPanelWidth = roomPanelWidth;
     ...........................

             ............................................

  GUILayout.BeginArea(new Rect(userPanelPosX, userPanelPosY, userPanelWidth,      userPanelHeight));
     GUILayout.Box ("Users", GUILayout.ExpandWidth(true),   GUILayout.ExpandHeight(true));
     GUILayout.BeginVertical();
     GUILayout.BeginArea(new Rect(20, 25, userPanelWidth-40, userPanelHeight-40), GUI.skin.customStyles[0]);
     //userScrollPosition = GUILayout.BeginScrollView (userScrollPosition);        
     userScrollPosition = GUILayout.BeginScrollView (userScrollPosition, GUILayout.Width (150), GUILayout.Height (160));
     foreach (User user in currentActiveRoom.UserList) {
     GUILayout.Label(user.Name);
     }
     GUILayout.EndScrollView ();

     GUILayout.EndArea ();
     
     // Current user info
     GUILayout.BeginArea(new Rect(20, 25 + userPanelHeight - 70, userPanelWidth-40, 40));
     GUILayout.BeginHorizontal();
     GUILayout.Label("Logged in as " + smartFox.MySelf.Name);
     GUILayout.FlexibleSpace();
     if (GUILayout.Button("Logout")) {
         smartFox.Send( new LogoutRequest() );
     }
     GUILayout.EndHorizontal();

     GUILayout.EndArea ();
     GUILayout.EndVertical();
     GUILayout.EndArea ();
         
     // Room chat window
     chatWindow.Draw(chatPanelPosX, chatPanelPosY, chatPanelWidth, chatPanelHeight);
 }
Comment

People who like this

0 Show 4
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 Linus · Feb 14, 2014 at 01:26 PM 0
Share

i see that there is a difference in the call order of ShowChatGUI() and DrawLobbyGUI() when you use button.

avatar image Deepschalappatta · Feb 18, 2014 at 08:36 AM 0
Share

@Linus : PLEASE EXPLAIN...

avatar image Linus · Feb 18, 2014 at 09:29 AM 0
Share

Reading the code closer it is not the call order that is the problem, it is that when using the button, DrawLobbyGUI() only gets called when button is clicked.

avatar image Deepschalappatta · Mar 04, 2014 at 05:00 AM 0
Share

it works fine ... :)

1 Reply

· Add your reply
  • Sort: 
avatar image
Wiki

Answer by Linus · Feb 18, 2014 at 09:26 AM

ShowChatGUI() needs to be called from inside OnGUI so it is drawn on every frame. You can use a boolean setting to enable or disable the chat lobby.

Here is a example I experimented with

 using UnityEngine;
 using System.Collections;
 
 public class lobby : MonoBehaviour {
 
     public bool started;
     public GUISkin gSkin;
 
     public bool showChatLobby; //could as well be private, but like to see things like that in editor while developing
 
     void OnGUI() {
         if (!started) return;
         
         GUI.skin = gSkin;
         ShowChatGUI();
         if(showChatLobby){
             DrawLobbyGUI();
         }
     }
     
     
     public void ShowChatGUI(){
         
         
         if (GUI.Button (new Rect (10,Screen.height - 80,120,120), "Test Chat Button")) 
         {
             if(!showChatLobby){
                 showChatLobby = true;
             } else {
                 showChatLobby = false;
             }
             
 
             
         }
 
     }
     public void DrawLobbyGUI() {
         GUI.Box(new Rect(10,10,150,25), "test text");
     }
 }
Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

SmartFox SFSEvent.CONNECTION isn't calling 1 Answer

Multiple Cars not working 1 Answer

How to get A Camera Collision? 1 Answer

Wait for a animation to finish in unity3d 3 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