- Home /
Unity Photon Network - Text Mesh Sync
Hi, im making a chat for my game, i do have the chat working but i can not make it work using text meshes insted of one text for everyone and i can only find how to do so with just one text. Can someone help me?
Msg Code :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Message : Photon.MonoBehaviour {
public InputField messageField;
public TextMesh text;
GameObject player;
void OnJoinedRoom () {
if (text == null) {
if (photonView.isMine) {
text = GameObject.FindWithTag ("MessageText").GetComponent<TextMesh> ();
}
}
}
void Start(){
if (text == null) {
if (photonView.isMine) {
text = GameObject.FindWithTag ("MessageText").GetComponent<TextMesh> ();
}
}
}
void Update (){
if (photonView.isMine) {
if (Input.GetKeyDown (KeyCode.Return)) {
photonView.RPC ("SendMessage", PhotonTargets.All, messageField.text);
messageField.text = "";
}
}
}
[PunRPC]
void SendMessage(string message, PhotonMessageInfo info) {
text.text = message;
}
}
Hi,
is this game object already placed in the scene [one object] or does it get instantiated with a character using PhotonNetwork.Instantiate(...) [multiple objects]? Is FindWithTag("$$anonymous$$essageText")
actually called? This may also cause some problems if you have multiple objects with the same tag.
@ChristianSimon sorry for late reply, the object is alredy there, it is instantiated with the player. (The message object is inside the player) The idea is i send a msg then it sets the text and after some seconds its cleaned out!
the object is alredy there
If I understand you correct you have placed the player object inside the scene, haven't you? The better option is to instantiate the object using PhotonNetwork.Instantiate(...) after having joined the room using OnJoinedRoom() callback. This makes sure, that every client gets his own game object. If you have already done this, I misunderstood your posting.
Again if you have multiple player objects, FindWithTag(...) won't return the correct object for sure. Since the Text$$anonymous$$esh object is placed 'inside' the player, you better use GetComponent() or GetComponentInChildren() do definitely get the correct object in order to store the reference.