How to make a prefab remember a public gameObject?

I am making a survival game and i have a problem.
I made it so the way you pick up items needs to remember a gameobject because the script is on the item itselft, but when i instantiate the object it doesnt remember that gameobject.
How do i fix this?
(I dont know everything about scripting yet)

script for the object “stick” :

private bool Collect;
public GameObject gameobject;
private Inventory inventory;

void Start()
{
    inventory = gameobject.GetComponent<Inventory>();

    Collect = false;
}

void Update()
{
    if (Collect == true)
        if (Input.GetButton("pickup"))
        {
            inventory.sticks += 1;
            Destroy(gameObject);
        }
}

void OnTriggerEnter(Collider other)
{
    if (other.gameObject.name == ("collector"))
    {
        Collect = true;
    }
}

void OnTriggerExit(Collider other)
{
    if (other.gameObject.name == ("collector"))
    {
        Collect = false;
    }
}

(collector is a dot in the middle of the screen that has a long block collider and is attached to the camera)

instead of Destroy(gameObject);
do

gameObject.enabled = false;

And from the moment you know that you can 100% remove the item
then you destroy it

If I undersand correctly; You should make that variable private and in start get a reference to it, like so:


    gameobject= GameObject.FindGameObjectsWithTag("YourTag");

Just create a tag inside the inspector and assign it to your object, then replace “YourTag” with the name of the tag you’ve created.