I’m making a flashcard game and want to add a flashcard from a list to the scene with a button press. I can add the cards to the scene but sometimes they end up on the same layer as the previous flashcard and i can’t see it. I would like it if each time i add a new flashcard from the list it ends up on the next layer (infront of the previous card) so i can see it, but i think it would be better to completely remove the previous flashcard when i press the button to add the next. How do i do that?
Here is what i have so far.
public class ListManager : MonoBehaviour
{
public List characterPrefabs = new List();
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.RightArrow))
{
if (characterPrefabs.Count > 0)
{
int characterIndex = Random.Range(0, characterPrefabs.Count);
Instantiate(characterPrefabs[characterIndex], new Vector3(0, 0, 0), characterPrefabs[characterIndex].transform.rotation);
characterPrefabs.RemoveAt(characterIndex);
}
if (characterPrefabs.Count == 0)
{
Debug.Log("Game Over");
}
}
}
}