Remove audioclip from list

Hi! I’m wondering how to remove specifically the last played audioclip from a list. I have a list with a bunch of audioclips (32), and I want to remove that clip as soon as the clip stops, since every audioclip is only allowed to be played once. I’ve tried everything but no one online seems to have had this problem :slight_smile:

Hi! There is a List.RemoveAt method which should be what you’re looking for, you can do something like this:

myList.RemoveAt(myList.Count - 1)

Hi! thanks for your answer, unfortunately my code doesnt recognize .remove at. When i type that isreadonly pops up. Perhaps something is wrong with visual studio. Thanks though!

I cant seem to send an image, so here’s some code.

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


public class SoundControl : MonoBehaviour
{
    public AudioClip[] sounds;
    private AudioSource source;


    private void Start()
    {
        source = GetComponent<AudioSource>();

    }

    public void Update()
    {

        Play();
    }

    IEnumerator Play()
    {
        if (Input.GetKeyDown(KeyCode.S))
        {
            source.clip = sounds[Random.Range(0, sounds.Length)];
            source.PlayOneShot(source.clip);

        }

        

        yield return null;

       
    }
}