Hi comm unity!
Im neither scripter nor unity wizz, but have managed to set up a small scene with a chat with loads of help from a smartfox island tutorial.
A lot is still abracadabra to me…, but learning ![]()
my question is:
I have instantiated players with a GUIText attached and a script named ObjectLabel that makes the GUItext follow the player object.
that works very nice, but it would be so cool to have the usernames hovering above the player object
and more precise…, dynamically the one that they logged on with smartfox.
How do I get the username that they logged on with in smartfox to that hovering GUIText?
I know the username data must be somewhere,
but not able to send it to the GUIText ![]()
I see this in the chatController.cs script where the username shows up in chat:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
using SmartFoxClientAPI;
using SmartFoxClientAPI.Data;
public class ChatController : MonoBehaviour {
public GUISkin skin;
private Vector2 scrollPosition;
private List<String> messages = new List<String>();
private Rect chatWindow;
private string userMessage = "";
private bool typingMessage = false;
private bool sendingMessage = false;
void Start() {
//chatWindow = new Rect(Screen.width-Screen.width, Screen.height - Screen.height/5, Screen.width /2.5f, Screen.height/5);
}
void OnGUI() {
GUI.skin = skin;
chatWindow = new Rect(Screen.width-Screen.width, Screen.height - Screen.height/1.5f, Screen.width /4.4f, Screen.height/1.5f);
if (EnterPressed()) {
if (!typingMessage) {
typingMessage = true;
}
else {
// Send message
if (userMessage.Length > 0) {
AddMyChatMessage(userMessage);
userMessage = "";
}
typingMessage = false;
}
Event.current.Use();
}
chatWindow = GUI.Window (1, chatWindow, ShowChatWindow, "Party Island");
}
private bool EnterPressed() {
return (Event.current.type == EventType.keyDown Event.current.character == '\n');
}
void ShowChatWindow(int id) {
GUI.SetNextControlName("scroll");
scrollPosition = GUILayout.BeginScrollView (scrollPosition);
foreach(string message in messages) {
GUILayout.BeginHorizontal();
GUILayout.Label(message);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.Space(3);
}
GUILayout.EndScrollView();
if (!typingMessage) {
GUI.FocusControl("scroll");
}
GUI.SetNextControlName("text");
userMessage = GUILayout.TextField(userMessage);
if (typingMessage) {
GUI.FocusControl("text");
}
GUILayout.Label("Press Enter to type and again to send");
}
private void AddMyChatMessage(String message) {
SmartFoxClient client = NetworkController.GetClient();
String userName = client.myUserName;
AddChatMessage(userName+": "+message);
SendChatMessage(message);
}
// This method to be called when remote chat message is received
void AddChatMessage(String message) {
messages.Add(message);
scrollPosition.y = 10000000000; // To scroll down the messages window
}
// Send the chat message to all other users
private void SendChatMessage(String message) {
SmartFoxClient client = NetworkController.GetClient();
client.SendPublicMessage(message);
}
}
can someone give me an example please?
must be beginner proof ![]()
Thanks