I wanna know how I can destroy the game object that was instantiated
if (previousRockAmount == 0)
{
if (previousRockAmount != rockAmount)
{
GameObject obj = Instantiate(rockImage, Vector3.zero, Quaternion.identity, transform);
obj.GetComponent<RectTransform>().localPosition = GetPosition(itemIdentifier - 1);
obj.GetComponentInChildren<TextMeshProUGUI>().text = rockAmount.ToString("n0");
previousRockAmount = rockAmount;
if (rockAmount == 0)
{
Destroy(obj);
}
}
}