Hi, I’m trying to create a debug class that when instanced, will create an object with a textmesh so I can display debug text where ever the object is. This is where I am up to so far (just creating the object and passing the text) and I’m putting the call in the update function jsut for testing.
Here is the code:
private var numberofObjects: int =0;
class DebugText
{
var passedtext;
//This is the constructor
function DebugText(textToDisplay: String)
{
//Incrememnt number of objects being created so we can name them individually
numberofObjects++;
//Generate name
var objectName : String = "DebugText"+numberofObjects;
//Need to add 3D Text gameobject
DebugTextObject = new GameObject (objectName);
DebugTextObject.AddComponent ("TextMesh");
currentMesh= DebugTextObject.GetComponent(TextMesh);
currentMesh.text=textToDisplay;
}
}
function Update()
{
ant = DebugText("anT");
}
A couple of questions:
- Unity complains that numberofObjects is an unknown identifier - I’ve no idea why.
- I’m concerned that after I create the object and add the component textmesh, that I’m accessing it incorectly - I previously tried DebugTextObject.TextMesh.text but it said textmesh wasnt a member of gameobject…
I feel I’m tieing myself in knots over this one. As I side note, I’m also noticing that Unity isn’t consistently reporting the same error. ie. I can run this code again and it wouldnt necessarily report that numberofObjects is an unknown identifier…odd.
Any help would be greatly appreciated.