Text display

This isn’t working, need help

public Text display;
public string displayText;
public Transform player;
private bool m_isTextShown;

void Start()
{
UpdateText(false);
}

void Update()
{
float dist = Vector3.Distance(transform.position, player.position);

if (dist <= 3f && !m_isTextShown)
{
UpdateText(true);
}
else if (dist > 3f && m_isTextShown)
{
UpdateText(false);
}
}

private void UpdateText(bool showText)
{
m_isTextShown = showText;
display.text = (showText) ? displayText : “”;
}

}

Check the first post in this forum for how to format your code to display properly in the forum.

Also, you gotta explain better than “isn’t working.” Start here:

  • what do you expect this code to do?
  • what is it actually doing?
  • did it work in the past?
  • are you seeing any errors in the console?

Did you add

using UnityEngine.UI;

at the top of your script and create the text object?

3882523--329962--Sans titre-1.jpg

i added that already

Please state clearly exactly what problem you are having or you are just wasting people’s time by making them guess.

1 Like