I have an object which has a script, when there are 2 raycasts hitting 2 other objects it will destroy the other 2 objects and itself.
if(transform.parent.GetComponent<Molecule>().test){
hit.transform.parent.GetComponent<Molecule>().test2 = true;
}
When the objects get destroyed I get an error on the line:
hit.transform.parent.GetComponent<Molecule>().test2 = true;
Can someone explain the reason behind this? when test2 is true it will destroy the object.
When pressing the error in Unity it also does not direct me to an object causing the error, meaning it got destroyed (right?) the game pauses because of this every single time.
the error:
NullReferenceException: Object reference not set to an instance of an object
Cylinder.Update () (at Assets/Scripts/Cylinder.cs:18)
Thanks!