Changing a variable in another script

Hello. This is driving me nuts, so I hope you can help me…

Ive tried to explain it as simple as possible, and i’ve commented every line on the script screenshots.

Right, so… I am making a 2D, top down game.
The scripts I post are for a supplybox and a aircraft(C130)

My idea is that the supplybox is invisible until the aircraft has flown over its position. Thats fine and working, but I want the aircraft to be Destroy()'ed afterwards, and heres where the problem is.

The aircraft should be destroyed when its x-units away from the player when it has passed the supplybox’s position(delivering the box).

So when the box has been changed to visible, it would change the “isDelivered” variable in the aircraft script, to true.

But I keep getting:
“Object reference not set to an instance of an object” at the line where it tries to change “isDelivered” to true.

I hope you guys can help…
I even tried making 2 new scripts and tried to change a variable in scriptB from scriptA.
It worked :x - So im really lost…


ensure you don’t make the game object inactive, otherwise your finds will not work as find only checks active game objects.

if you only need it to be invisible, instead just disable the renderer on the object.

alternatively, if possible, you can also make the _c130 reference public and drag-n-drop in the the reference in the editor, then enabled is no longer needed

Thanks for the reply.

The only thing im doing to the box is changing its materials alpha value and making its collider a trigger(just so its ignored by physics while its invisible)

The box’s script is the one Instantiating the C130, but I placed the GetComponent(); after the Instantiating, so the C130 should be active. Right?

EDIT: Right, so I think ive found the problem.
The box, which is spawning the aircraft, needs to change one of its variables. But since the aircraft isnt active when the box is, the problem occurs.

What could I do?