리스트 사용 네임스페이스 using System.Collection.Generic

리스트 사용 네임스페이스 using System.Collection.Generic

List<GameObject> orcs = new List<GameObject>();
리스트의 데이터형은 GameObject 이다.



using UnityEngine; using System.Collections; using System.Collections.Generic; public class box : MonoBehaviour { public GameObject[] anemy; List<GameObject> orcs = new List<GameObject>(); // Use this for initialization void Start () { foreach (GameObject cbox in anemy) { if( cbox.tag == "Orc"){ orcs.Add(cbox); // list Ores 에 cbox를 추가한다. } } } void OnMouseDown(){ Allgreen (); for (int i = 0; i < orcs.Count; i ++) { // 리스트의 크기는 length로 찾는것이 아니라 count로 찾는다. orcs[i].GetComponent<Renderer>().material.color = Color.red; } if (orcs.Count > 0) { orcs.RemoveAt (orcs.Count - 1); // orcs 리스트 첫번째 요소를 뺀다. } else if (orcs.Count == 0) { for(int i = 0; i < anemy.Length; i ++){ orcs.Add (anemy[i]); } } } void Allgreen(){ for (int i = 0; i < anemy.Length; i ++) { anemy[i].GetComponent<Renderer>().material.color = Color.green; } } // Update is called once per frame void Update () { } }

댓글

이 블로그의 인기 게시물

날짜 시간 시간차 시간 계산 하기

코루틴에서 CallBack 함수 적용하기

C++ 언어 퍼센트 구하는 방법 / 기본 언어 퍼센트 구하는 방법