Hi, I’m relatively new to Unity, and have a quick question regarding some code of mine that isn’t working quite like I would expect. I have an GameObject called Dude, that is destroyed upon the player colliding with it. That seems to work just fine. However, I have another game object called SpeechBubble that draws a GUITexture at the location of the Dude object. This also works. However, in the update of the SpeechBubble object I have the following code:
void Update()
{
if (target == null)
{
DestroyObject(gameObject);
}
else
{
thisTransform.position = Camera.main.WorldToViewportPoint(target.position + offset);
}
}
Target is set to the Dude GameObject, and this almost works fine, except that the else code seems to run even after the Dude object is destroyed once. Also, the speech bubble is destroyed almost a second after the Dude is destroyed, and therefore null.
I thought that objects were destroyed after all update calls. Sorry if this is really simple, but it’s just kinda confusing me.