unity When I pick up an object from the ground, the object disappears. I want him to come back after a while.

The object is lost when picking up an object from the ground. I want him to come back after a while.

I am using a bag system when i click on the object on the ground the object (setactive = false) I want it to come back in the same place after a while.
Like picking up food from the ground in games.
I tried this with elapsed but failed.
Here is my code that doesn’t work

public class ItemPickUp : MonoBehaviour
{
  public Item Item;

  public GameObject gameobj;
  float elapsed;

  void Pickup()
  {
    InventoryManager.Instance.Add(Item);
    gameobj.SetActive(false);
  }
  
  private void OnMouseDown()
  {
    Pickup();
  }

  void Update()
  {
    if(gameobj.SetActive(false))
    {
      elapsed += Time.deltaTime;
    if (elapsed >= 2f) 
    {
      elapsed = elapsed % 1f;
      gameobj.SetActive(true);
    }
    }
  }
}

if(gameobj.SetActive(false))
This line is not checking if gameobj is active or not.
Be careful for what methods return, and what does that return value means.
From the documentation: public void SetActive(bool value);
SetActive is a void method, it means it returns nothing for you to read.
SetActive is the method you call to set your object active or not.


To check if a gameobject is active, use instead gameobj.activeInHierarchy which returns a bool true or false, based on the state of the object in hierarchy.
In your case, you can replace the line of code if(gameobj.SetActive(false)) with if(gameobj.activeInHierarchy == false) to check if gameobj is not active.

GameObject.activeInHierarchy

I did it as you said, the game did not give an error, but still what I tried to do does not work.
Can this be done any other way?