- Home /
Question by
frackfrick · Aug 06, 2015 at 05:19 PM ·
textnetworkphotonupdate
Using Photon View To update Text over the network
I'm Making a multiplayer FPS game and I want to give each player a 3d text object that they can write in whenever they want. everything is working fine except that other players don't see the 3d text updating. Ive added a photon view component to the text, but letting it observe the text mesh or mesh renderer doesn't work and gives me these errors:
Observed type is not serializable: UnityEngine.MeshRenderer Observed type is not serializable: UnityEngine.TextMesh
Is there some other component I need to view?
Comment
Answer by satyagames · Aug 17, 2015 at 09:20 AM
PlayerNetWorkMover Script :- (To update a Text (Player names) over a network)
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
public class PlayerNetworkMover : Photon.MonoBehaviour {
public string playerName;
private Transform _transformCacheName;
private Transform _playerTransformName;
void Start ()
{
_transformCacheName = GetComponent<Transform>();
_playerTransformName = _transformCacheName.FindChild("NameText");
if(photonView.isMine)
{
GetComponentInChildren<PlayerNameScript>().enabled = true;
}
else
{
StartCoroutine("UpdateData");
}
}
IEnumerator UpdateData()
{
while(true)
{
playerName = _playerTransformName.GetComponent<TextMesh>().text;
yield return null;
}
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if(stream.isWriting){
stream.SendNext(_playerTransformName.GetComponent<TextMesh>().text);
}else{
_playerTransformName.GetComponent<TextMesh>().text = (string)stream.ReceiveNext();
}
}
}
PlayerNameScript :- (You should attack this script at you player head)
using UnityEngine;
using System.Collections;
public class PlayerNameScript : MonoBehaviour {
string playerName;
void Update () {
//playerName = GameControl.control.c_id;
GetComponent<TextMesh> ().text = playerName;
}
}
networkmover.png
(90.9 kB)
Thank you. great work. This just helped me so much :)