Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

[VERY URGENT 4Hours LEFT!]Displaying other's speech bubble

Discussion in 'Immediate Mode GUI (IMGUI)' started by unitygirl, Jun 22, 2010.

  1. unitygirl

    unitygirl

    Joined:
    May 25, 2010
    Posts:
    38
    Hi!

    I'm currently trying to make speech bubble when people connected to the game type something on chat window.

    I was able to make myself a speech bubble which hovers above my character which works fine, but thing is when other people chats and when speech bubble appears, it doesn't quite get positioned properly according to their position through my camera's sight. especially it doesn't work when they go out of my sight and stuff.

    So could anyone please help?! I've been trying this for such a long time and now I don't have much time left...

    I will really be appreciated if anyone come up with well modified code of below:

    Code (csharp):
    1.  
    2. //locks gui text to objects position
    3. //doesn't work perfectly unless orthographic camera chosen
    4. var chatWindow: ChatWindow_test; //to refer ChatWindow_test script
    5. var chatWinObj: GameObject; //to store ChatWindow Object found.
    6.  
    7. //GUI Styles and Skins
    8. private var customGuiStyle : GUIStyle;
    9. public var chatfont : Font;
    10. public var defaultGuiSkin :GUISkin;
    11.  
    12. //callout positoin info
    13. var screenPosition: Vector3;
    14. var offsetX = 100; //try to correct x position
    15.  
    16. var callouts: Texture2D; //texture of callout
    17.  
    18. var textAlign: TextAnchor;
    19. var chatWrap: boolean;
    20.  
    21. public var bubbleText =""; //text to be appeared on callouts
    22.  
    23. var chatLines="";
    24. var playerName="";
    25.  
    26. var calloutTarget:GameObject;
    27.  
    28. function Start()
    29. {
    30.     //set gui styles
    31.     customGuiStyle = new GUIStyle();
    32.     customGuiStyle.font = chatfont;
    33.     //set chatwindow
    34.     chatWinObj = GameObject.Find("ChatWindow");
    35.     chatWindow = chatWinObj.GetComponent("ChatWindow_test");
    36. }
    37.  
    38. function Update()
    39. {  
    40.     bubbleText = chatWindow.bubbleChat; //update text from chatwindow_test every frame
    41. }
    42.  
    43.  
    44. function OnGUI (){  
    45.     if(networkView.isMine)
    46.     {
    47.         if(bubbleText != "") //something has been stored on bubble text = user typed something
    48.         {
    49.             GUI.skin = defaultGuiSkin; //apply skin
    50.            
    51.             //color, callout, alignment and textwrapping
    52.             customGuiStyle.normal.textColor = Color(1.0, 1.0, 0.0);
    53.             customGuiStyle.normal.background = callouts;
    54.             customGuiStyle.alignment = textAlign;
    55.             customGuiStyle.wordWrap = chatWrap;
    56.            
    57.             //gui position
    58.             screenPosition = camera.main.WorldToScreenPoint(transform.position);
    59.             GUI.Box(Rect(screenPosition.x - offsetX, screenPosition.y -60, 200, 100),bubbleText,customGuiStyle);
    60.         }
    61.         var playerInfo = gameObject.name;
    62.         networkView.RPC("showCallouts", RPCMode.OthersBuffered, playerInfo, bubbleText);
    63.     } else {
    64.         if(playerName !=""  chatLines !="")
    65.         {
    66.            
    67.             calloutTarget = GameObject.Find(playerName);
    68.             GUI.skin = defaultGuiSkin; //apply skin
    69.            
    70.             //color, callout, alignment and textwrapping
    71.             customGuiStyle.normal.textColor = Color(1.0, 1.0, 0.0);
    72.             customGuiStyle.normal.background = callouts;
    73.             customGuiStyle.alignment = textAlign;
    74.             customGuiStyle.wordWrap = chatWrap;
    75.             screenPosition2 = camera.main.WorldToScreenPoint(calloutTarget.transform.position);
    76.             GUI.Box(Rect(screenPosition2.x  - offsetX, screenPosition2.y-60, 200, 100),chatLines,customGuiStyle);
    77.            
    78.         }
    79.     }
    80. }
    81.  
    82. @RPC
    83. function showCallouts(playInfo:String, chatWords:String)
    84. {
    85.     playerName = playInfo;
    86.     chatLines = chatWords;
    87. }
     
  2. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    I guess this is probably too late now, but... can you describe in a bit more detail what is going wrong with the bubbles and how you would like them to look?