How to activate the child of an object without declaring a public transform?

My script is pretty simple. It involves a stick which I want to pick up, so when I walk into the box collider it is triggered and if I press E the stick is destroyed.

The problem is that I have a small floating ‘E’ above the stick so that the player knows which button to press in order to pick up the stick, this ‘E’ appears when you walk into the collider and is a child of the stick.

So when I destroy the stick I get an error saying that I am still trying to access the object after I have destroyed it. This is because I have publicly declared the child transform. Is there another way to setActive() the child of the stick without having to publicly declare the transform?

Here is my code…

using UnityEngine;
using System.Collections;

public class PlayerInv : MonoBehaviour {

public GameObject interactIcon;


void OnTriggerStay(Collider col){
	if(col.gameObject.CompareTag("Stick"))
	{
		interactIcon.gameObject.SetActive (true);
		if(Input.GetKeyDown(KeyCode.E))
		{
			Destroy(col.gameObject);
		}
	}
}

void OnTriggerExit(Collider col){
	if(col.gameObject.CompareTag("Stick"))
	{
		interactIcon.gameObject.SetActive (false);
	}
	Debug.Log ("exiting collider");
}

}

" error […] because I have publicly declared the child transform."

No. That’s not true. It’s like saying your fingers are smashed because your car has doors. The real problem is that you’re using it wrong.

I think stepan_stulov is correct. Are you destroying the E marker? Pause the game and look for it. Do you want to destroy it? If not, how can you avoid it’s destruction?