Hi Devs, i am new to game development.
I want to change my player every X seconds. For that i am destroying the previous prefab and instantiating the new prefab.
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);
}
But the prefab is not destroying.
How can i destroy the prefab and instantiate the new prefab on the previous position.
Is it the correct approach for this?