Changing 3D text through script

So basically, I want a script that shows the number of “players_knights” in a 3D text, but I’ve searched everywhere and have tried everything but haven’t been able to get anything to work. so can someone help me make this script be able to show on to a 3D text? (oh and the most common problem I’ve had is "Cannot convert “int” to “String” " something like that.)

SCRIPT:

var players_knights = 20;

function Update() {

}

1 Answer

1

I seriously doubt that you’ve searched ‘everywhere’ and tried ‘everything’. I tried this, and it worked.

using UnityEngine;
using System.Collections;

public class Text : MonoBehaviour
{
	private TextMesh text;
	
	void Awake()
	{
		text = gameObject.AddComponent<TextMesh>();
		
		text.text = Time.time.ToString();
	}
	
	void Update()
	{
		text.text = Time.time.ToString();
	}
}

thanks a bunch :D, but would it be ok if it was java script? I just have never used C#.

Sure, you can do the same stuff in JavaScript. This isn't a site to come and have other people do your coding though, the above was just an example. It's really easy to convert this in to js, so give it a shot! If you have problems, then come back and ask a specific question. :)

Is that maybe because you commented out the GetComponent line and so are no longer linking to the actual object?

Sir, I had no idea what was wrong with my code, and then realized I forgot the () after ToString. It's 3 am, I don't know why I felt the need to make an account and thank you.