Question by
tim-wheeler · Oct 17, 2019 at 06:24 PM ·
triggertexttextmesh
textmesh OnTriggerEnter
Hi Sry for being thick Im trying to use the textMesh "simple code" example to get the score to add up in the textmesh. when ever i trigger. the score code works in the Update but if i put it in:
if (m_triggering) { blah score dam you blah} it stops working.
or even if i put it in:
void OnTriggerEnter(Collider other) it stops as well.
Any ideas please.
namespace TMPro.Examples
{
public class SimpleScriptTim : MonoBehaviour
{
private TextMeshPro m_textMeshPro;
//private TMP_FontAsset m_FontAsset;
private const string label = "The <#0050FF>count is: </color>{0:2}";
//private int m_frame;
//===========
private GameObject m_triggeringNpc;
private bool m_triggering;
private int m_score;
void Start()
{
// Add new TextMesh Pro Component
m_textMeshPro = gameObject.AddComponent<TextMeshPro>();
m_textMeshPro.autoSizeTextContainer = true;
// Load the Font Asset to be used.
//m_FontAsset = Resources.Load("Fonts & Materials/LiberationSans SDF", typeof(TMP_FontAsset)) as TMP_FontAsset;
//m_textMeshPro.font = m_FontAsset;
// Assign Material to TextMesh Pro Component
//m_textMeshPro.fontSharedMaterial = Resources.Load("Fonts & Materials/LiberationSans SDF - Bevel", typeof(Material)) as Material;
//m_textMeshPro.fontSharedMaterial.EnableKeyword("BEVEL_ON");
// Set various font settings.
m_textMeshPro.fontSize = 48;
m_textMeshPro.alignment = TextAlignmentOptions.Center;
//m_textMeshPro.anchorDampening = true; // Has been deprecated but under consideration for re-implementation.
//m_textMeshPro.enableAutoSizing = true;
//m_textMeshPro.characterSpacing = 0.2f;
//m_textMeshPro.wordSpacing = 0.1f;
//m_textMeshPro.enableCulling = true;
m_textMeshPro.enableWordWrapping = false;
//textMeshPro.fontColor = new Color32(255, 255, 255, 255);
}
void Update()
{
m_textMeshPro.SetText(label, m_score);
m_score +=1;
print("score is " + m_score);
if (m_triggering)
{
print("PlayerLeftHand is triggering with " + m_triggeringNpc);
}
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("npc"))
{
m_triggering = true;
m_triggeringNpc = other.gameObject;
}
}
void OnTriggerExit(Collider other)
{
if (other.CompareTag("npc"))
{
m_triggering = false;
m_triggeringNpc = null;
}
}
}
}
<code>
Comment
Answer by tim-wheeler · Dec 05, 2019 at 10:29 PM
Ok i gave up on that you cant use textmesh in that way as far as i can see