Hey Aren!
I've finally downloaded the newest Tnet so I could use the WorldChat
feature.
However, it does not seem to work.
When writing new messages and using target.broadcast instead of target.all.
No new messages show up.
I even tried with more than one client online at the same time to check if it was just because it only worked if it detected more than one client.
I also tried moving one of the clients to a different scene (Still connected to the same server) and then trying it out. Same deal. (I'm using the inbuilt server solution, not the external one)
Any chance you could tell me how to use it?
I'll post the code so you can see if the error is on my part:
[RequireComponent
(typeof(TNObject
))] public class UIGameChat : UIChat
{
TNObject tno;
/// <summary>
/// Sound to play when a new message arrives.
/// </summary>
public AudioClip notificationSound;
/// <summary>
/// If you want the chat window to only be shown in multiplayer games, set this to 'true'.
/// </summary>
public bool destroyIfOffline = false;
/// <summary>
/// We want to listen to input field's events.
/// </summary>
void Start ()
{
if (destroyIfOffline && !TNManager.isInChannel)
{
Destroy(gameObject);
}
else tno = GetComponent<TNObject>();
tno.rebuildMethodList = true;
}
/// <summary>
/// Send the chat message to everyone else.
/// </summary>
protected override void OnSubmit (string text)
{
tno.Send("OnChat", Target.Broadcast, TNManager.playerID, text);
}
[RFC]
void OnChat(int playerID, string text)
{
Color color = Color.white;
Player sender = TNManager.GetPlayer(playerID);
if (sender != null)
{
// If the message was not sent by the player, color it differently and play a sound
if (playerID != TNManager.playerID)
color
= new Color
(0
.6f, 1
.0f, 0f
);
// Embed the player's name into the message
text = string.Format("[{0}]: {1}", sender.name, text);
}
Add(text, color);
if (notificationSound != null)
NGUITools.PlaySound(notificationSound);
}
void OnNetworkPlayerJoin (Player p) { Add(p.name + " has joined the game."); }
void OnNetworkPlayerLeave (Player p) { Add(p.name + " has left the game."); }
}
(I think that chat code is from the StarLink game, I'll try with some of the other chat examples as well just to be sure though.)