- Home /
MissingReferenceException error.
Hello. I got most of the things from my first question (here) to work but I have a new problem. As the title says I get that error when I successfully destroy a meteor. The guiText attached to it however doesn't get destroyed with it and I get the error ": The object of type 'Transform' has been destroyed but you are still trying to access it." Double clicking brings up ObjectLable.js to the line:
thisTransform.position = cam.WorldToViewportPoint(target.position + offset);
I've tried adding Destroy commands to the collision script, even tried adding:
if(target == null)
{
Destroy(this);
}
After that previous line of code. I've tried remaking my meteorPrefab with textPrefab as a sub-component with no better results.
Thanks in advance for assistance.
Answer by FTheCloud · Sep 14, 2011 at 11:39 PM
When you say :
if(target == null)
{
Destroy(this);
}
Your telling unity to destroy the script. If you want to destroy the entire gameobject use:
if(target == null)
{
Destroy(gameObject);
}
That's one of the variations I've tried. I put that in the ObjectLabel script and it doesn't work.
Still haven't gotten this to function right. I'm going in circles here. I've tried to do a null check in both the ObjectLabel script and my spawning script.
if (text.GetComponent(ObjectLabel.target == null) { Destroy(transform.text); }
If I put the the previous code suggested in the start function the text doesn't pop up at all. If I add it to the end of the update function of ObjectLabel.js it does nothing.