My apologies. Could this thread please be removed. Or at the very least the code posted.
I'm not exactly clear on what's going on... but my best suggestion is: are you sure you're using OnMouseDown() properly? Are you sure you don't want to be using this instead?:
function Update()
{
if(Input.GetKeyDown("mouse 0"))
{
toString();
}
}
Additionally, you should look into using String.Format() instead of just concatenating everything. It makes your code a lot easier to read. (The code is in .NET languages (like C#), but it can be used with Javascript in the same way.) Just a suggestion ;)
Looking it over again... you said the problem was "flickering" text, like multiple text objects were being drawn at the same time, correct?
When using inheritance, if you create an "Adult", for example, it also creates a "Person". So if you have two "Adults", then, technically, you also have two "Person" objects (programming objects, not game objects). I'm assuming that if you have multiple villagers, then you have multiple instances of the "Person" class, and therefore, multiple text objects all trying to draw in the same position, at the same time.
What you probably need to do is have some sort of flag (read: boolean variable) to determine whether or not the GUIText should draw or not. Here's one way of doing it:
- In the `Person` class, have a bool variable, something like "drawDebugText". Make sure it's false to start with.
- When the user clicks on a villager, loop through every villager and set "drawDebugText" to false. Then set the one that you just clicked on, to true.
- In `OnGUI()`, have something like `if(drawDebugText) { // draw here // }`
If you're not sure about how to loop through all villagers, consider adding a tag or component that will allow you to find all of them at once.
(Also, hooray for 3 answers :) )