C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class AI2 : MonoBehaviour { 6 7 public float timeOut = 3; 8 private Vector3 Cre_Pos1; 9 private Vector3 Cre_Pos2; 10 private Vector3 Cre_Pos3; 11 private Vector3 Cre_Pos4; 12 private Vector3 Cre_Pos5; 13 private Vector3 Cre_Pos6; 14 private Vector3 Cre_Pos7; 15 private Vector3 Cre_Pos8; 16 private List<GameObject> TmpList; 17 18 // Use this for initialization 19 void Start () { 20 StartCoroutine(Move()); 21 } 22 23 // Update is called once per frame 24 void Update () { 25 26 } 27 28 IEnumerator Move() 29 { 30 while (true) 31 { 32 Vector3 Pos = transform.position; 33 Vector3 Pos1 = new Vector3(Pos.x - 16, Pos.y + 16, Pos.z); 34 Vector3 Pos2 = new Vector3(Pos.x - 16, Pos.y, Pos.z); 35 Vector3 Pos3 = new Vector3(Pos.x - 16, Pos.y - 16, Pos.z); 36 Vector3 Pos4 = new Vector3(Pos.x, Pos.y - 16, Pos.z); 37 Vector3 Pos5 = new Vector3(Pos.x + 16, Pos.y - 16, Pos.z); 38 Vector3 Pos6 = new Vector3(Pos.x + 16, Pos.y, Pos.z); 39 Vector3 Pos7 = new Vector3(Pos.x + 16, Pos.y + 16, Pos.z); 40 Vector3 Pos8 = new Vector3(Pos.x, Pos.y + 16, Pos.z); 41 42 GameObject[] Creatures = GameObject.FindGameObjectsWithTag("Creature"); 43 var list = new List<GameObject>(); 44 list.AddRange(Creatures); 45 foreach (GameObject Cre in list) 46 { 47 TmpList = new List<GameObject>(); 48 TmpList.Add(Cre); 49 } 50 foreach (GameObject Cre in TmpList) 51 { 52 if (Cre.transform.position == Pos) 53 { 54 list.Remove(Cre); 55 } 56 if (Cre.transform.position == Pos1) 57 { 58 Cre_Pos1 = Cre.transform.position; 59 } 60 if (Cre.transform.position == Pos2) 61 { 62 Cre_Pos2 = Cre.transform.position; 63 } 64 if (Cre.transform.position == Pos3) 65 { 66 Cre_Pos3 = Cre.transform.position; 67 } 68 if (Cre.transform.position == Pos4) 69 { 70 Cre_Pos4 = Cre.transform.position; 71 } 72 if (Cre.transform.position == Pos5) 73 { 74 Cre_Pos5 = Cre.transform.position; 75 } 76 if (Cre.transform.position == Pos6) 77 { 78 Cre_Pos6 = Cre.transform.position; 79 } 80 if (Cre.transform.position == Pos7) 81 { 82 Cre_Pos7 = Cre.transform.position; 83 } 84 if (Cre.transform.position == Pos8) 85 { 86 Cre_Pos8 = Cre.transform.position; 87 } 88 } 89 yield return new WaitForSeconds(timeOut); 90 } 91 } 92} 93
TmpList.Add(Cre);でlist内の要素を追加しているのですが、一つの要素しかTmpListに追加されません。どうすれば全ての要素を追加出来るのでしょうか?
回答お願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。