리스트에서 해당 인덱스부터 마지막까지 제거 하기
Unity3D/Problems 2014. 7. 3. 00:21using 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 () {
}
}
'Unity3D > Problems' 카테고리의 다른 글
StoreKit In App Purchase (0) | 2015.02.06 |
---|---|
NGUI UIInput한글 문제 (2) | 2014.09.01 |
Could not resolve host: C; No data record of requested type (0) | 2014.06.24 |
Many !IsFinite errors (0) | 2014.06.19 |
navMeshAgent 문제 ("SetDestination" can only be called on an active agent that has been placed on a NavMesh.) (0) | 2014.03.25 |