I am trying to rename 3d text over the players head. The problem is, when a 3 or more players connect, the other clients just displays the default text. The server and current player is only displaying their names.
demo: http://loredev.host56.com/Unity3/projectred2/WebPlayer.html
using UnityEngine;
using System.Collections;
public class cs_PlayerText3D : MonoBehaviour {
private Transform AccountTransform;
private Transform myCamera;
private Transform myTransform;
private TextMesh textMesh;
private string accountName = "";
// Use this for initialization
void Start()
{
textMesh = (TextMesh)gameObject.GetComponent(typeof(TextMesh));
myTransform = transform;
myCamera = Camera.main.transform;
if (networkView.isMine)
{
if (GameObject.FindWithTag("AccountData"))
{
AccountTransform = GameObject.FindWithTag("AccountData").transform;
accountName = AccountTransform.GetComponent<cs_AccountData>().sAccountName;
}
else
{
Debug.LogWarning("Cannot find [AccountData] gameobject!!");
textMesh.text = "Cannont Find Data";
}
networkView.RPC("fnSetName", RPCMode.All, accountName);
}
}
void Update()
{
myTransform.rotation = myCamera.rotation;
}
//===============================================================
// Networking
//===============================================================
[RPC]
void fnSetName(string msg)
{
textMesh = (TextMesh)gameObject.GetComponent(typeof(TextMesh));
textMesh.text = msg;
Debug.Log("Set 3D text name: " + msg);
}
void OnPlayerConnected()
{
networkView.RPC("fnSetName", RPCMode.OthersBuffered, accountName);
//Debug.Log("New player connected.");
}
}