The object is lost when picking up an object from the ground. 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

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

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);
    }
    }
  }
}

This post is duplicated: unity When I pick up an object from the ground, the object disappears. I want him to come back after a while. - Questions & Answers - Unity Discussions