The question is answered, right answer was accepted
Mouse over system not destroying mouse over after object death, fix?
ok so im working on a 2d space game where players can hover over other objects and see details about them and i cant for the life of me figure out a little bug that has appeared, here's the code for Reference:
`
public class MouseHover : MonoBehaviour
{
public GameObject MouseCircle;
GameObject Tracked;
bool Good = false;
void OnMouseOver()
{
if (Tracked == null)
{
Tracked = (GameObject)Instantiate(MouseCircle, gameObject.transform.position, Quaternion.identity);
}
else
{
Tracked.transform.position = gameObject.transform.position;
}
Good = true;
}
void LateUpdate()
{
if (Tracked.transform.position != gameObject.transform.position || Good == false )
{
Destroy(Tracked);
}
Good = false;
}
}
the problem is, is that if the object gets destroyed the mouse over is never destroyed leaving a rather ugly circle just sitting there.
any help would be much appreciated
-Mallen
Do you get NullRef errors from LateUpdate()? "Tracked" is null until a $$anonymous$$ouseOver.
No i don't actually get any error, it just doesn't destroy the mouse over if the Parent is destroyed
Answer by Mallen_ · Sep 04, 2015 at 08:37 AM
ok i fixed this myself by having the mouseover destroy itself on update and have it spawned on late update by the enemy, if more details are needed contact me