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:
//locks gui text to objects position
//doesn't work perfectly unless orthographic camera chosen
var chatWindow: ChatWindow_test; //to refer ChatWindow_test script
var chatWinObj: GameObject; //to store ChatWindow Object found.
//GUI Styles and Skins
private var customGuiStyle : GUIStyle;
public var chatfont : Font;
public var defaultGuiSkin :GUISkin;
//callout positoin info
var screenPosition: Vector3;
var offsetX = 100; //try to correct x position
var callouts: Texture2D; //texture of callout
var textAlign: TextAnchor;
var chatWrap: boolean;
public var bubbleText =""; //text to be appeared on callouts
var chatLines="";
var playerName="";
var calloutTarget:GameObject;
function Start()
{
//set gui styles
customGuiStyle = new GUIStyle();
customGuiStyle.font = chatfont;
//set chatwindow
chatWinObj = GameObject.Find("ChatWindow");
chatWindow = chatWinObj.GetComponent("ChatWindow_test");
}
function Update()
{
bubbleText = chatWindow.bubbleChat; //update text from chatwindow_test every frame
}
function OnGUI (){
if(networkView.isMine)
{
if(bubbleText != "") //something has been stored on bubble text = user typed something
{
GUI.skin = defaultGuiSkin; //apply skin
//color, callout, alignment and textwrapping
customGuiStyle.normal.textColor = Color(1.0, 1.0, 0.0);
customGuiStyle.normal.background = callouts;
customGuiStyle.alignment = textAlign;
customGuiStyle.wordWrap = chatWrap;
//gui position
screenPosition = camera.main.WorldToScreenPoint(transform.position);
GUI.Box(Rect(screenPosition.x - offsetX, screenPosition.y -60, 200, 100),bubbleText,customGuiStyle);
}
var playerInfo = gameObject.name;
networkView.RPC("showCallouts", RPCMode.OthersBuffered, playerInfo, bubbleText);
} else {
if(playerName !="" chatLines !="")
{
calloutTarget = GameObject.Find(playerName);
GUI.skin = defaultGuiSkin; //apply skin
//color, callout, alignment and textwrapping
customGuiStyle.normal.textColor = Color(1.0, 1.0, 0.0);
customGuiStyle.normal.background = callouts;
customGuiStyle.alignment = textAlign;
customGuiStyle.wordWrap = chatWrap;
screenPosition2 = camera.main.WorldToScreenPoint(calloutTarget.transform.position);
GUI.Box(Rect(screenPosition2.x - offsetX, screenPosition2.y-60, 200, 100),chatLines,customGuiStyle);
}
}
}
@RPC
function showCallouts(playInfo:String, chatWords:String)
{
playerName = playInfo;
chatLines = chatWords;
}