I am new to game development. I am trying to change the player prefab every X seconds. For that, I am destroying the previously spawned prefab and instantiating a new prefab. But I don't know how to DESTROY THE PREFAB (not the empty game object on which the script is attached)
This is my code :
[SerializeField]
public GameObject[] objectToSpawn;
public float ChangeInterval = 5;
public float timer;
private void Update()
{
int Rand = Random.Range(0, objectToSpawn.Length);
GameObject spawnPrefab = objectToSpawn[Rand];
timer += Time.deltaTime;
if (timer >= ChangeInterval)
{
Instantiate(spawnPrefab, transform.position, Quaternion.identity);
timer -= ChangeInterval;
}
Destroy(gameobject);
}
Please tell me how can I destroy the prefab. Also is this the correct approach for it?? Thank You.