- Home /
Build errors and textMeshPro
So guys i need to get this script so i can display my name over the network but i want to use textmeshpro can some one help me please?
Blockquote
also i'm getting an error : ShowInfoOfPlayer.cs(44,38): error CS0246: The type or namespace name 'TextMeshPro' could not be found (are you missing a using directive or an assembly reference?)
Blockquote
using UnityEngine;
using System.Collections;
using ExitGames.Client.Photon;
/// <summary>
/// Can be attached to a GameObject to show info about the owner of the PhotonView.
/// </summary>
/// <remarks>
/// This is a Photon.Monobehaviour, which adds the property photonView (that's all).
/// </remarks>
[RequireComponent(typeof(PhotonView))]
public class ShowInfoOfPlayer : Photon.MonoBehaviour
{
private GameObject textGo;
public TextMesh tm;
public float CharacterSize = 0;
public Font font;
public bool DisableOnOwnObjects;
void Start()
{
if (font == null)
{
#if UNITY_3_5
font = (Font)FindObjectsOfTypeIncludingAssets(typeof(Font))[0];
#else
font = (Font)Resources.FindObjectsOfTypeAll(typeof(Font))[0];
#endif
Debug.LogWarning("No font defined. Found font: " + font);
}
if (tm == null)
{
textGo = new GameObject("Text");
//textGo.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
textGo.transform.parent = this.gameObject.transform;
textGo.transform.localPosition = Vector3.zero;
MeshRenderer mr = textGo.AddComponent<MeshRenderer>();
mr.material = font.material;
tm = textGo.AddComponent<TextMeshPro>();
tm.font = font;
tm.anchor = TextAnchor.MiddleCenter;
if (this.CharacterSize > 0)
{
tm.characterSize = this.CharacterSize;
}
}
}
void Update()
{
bool showInfo = !this.DisableOnOwnObjects || this.photonView.isMine;
if (textGo != null)
{
textGo.SetActive(showInfo);
}
if (!showInfo)
{
return;
}
PhotonPlayer owner = this.photonView.owner;
if (owner != null)
{
tm.text = (string.IsNullOrEmpty(owner.NickName)) ? "player"+owner.ID : owner.NickName;
}
else if (this.photonView.isSceneView)
{
tm.text = "scn";
}
else
{
tm.text = "n/a";
}
}
}
Answer by wewewu · Jun 07, 2020 at 07:03 AM
if you want to use TextMeshPro, you need
using TMPro;
and use TextMeshProUGUI
instead.
So now i get this error
Assets\Photon Unity Networking\Demos\DemoChangeOwner\ShowInfoOfPlayer.cs(44,18): error CS0029: Cannot implicitly convert type 'T$$anonymous$$Pro.Text$$anonymous$$eshProUGUI' to 'UnityEngine.Text$$anonymous$$esh'
You must change all text mesh into Text$$anonymous$$eshProUGUI, i have no idea if it doesn't work
Your answer
Follow this Question
Related Questions
Vuforia needs to be played before the build works 0 Answers
Variables keep getting swapped with the other. 1 Answer
UNet Shooting Projectiles easy method? 0 Answers
Tanks!!! Multiplayer 0 Answers