리스트에서 해당 인덱스부터 마지막까지 제거 하기
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Block
{
private int _id;
public Block(int id)
{
this._id = id;
}
public int GetID()
{
return this._id;
}
}
public class Test : MonoBehaviour {
private List<Block> list;
// Use this for initialization
void Start () {
list = new List<Block> ();
for (int i = 0; i<5; i++) {
Block block = new Block (i);
list.Add (block);
Debug.Log(i.ToString());
}
int idx = 0;
foreach (Block b in list) {
if(b.GetID() == 3)
{
idx = list.IndexOf(b);
}
}
Debug.Log (idx.ToString ());
list.RemoveRange(idx, list.Count - idx);
Debug.Log (list.Count);
foreach (Block b in list) {
Debug.Log(b.GetID().ToString());
}
}
// Update is called once per frame
void Update () {
}
}