using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
public class BoardManager : MonoBehaviour
{
private List<Transform> pathFieldsPositions = new List<Transform>();
private List<Transform> finishFieldsPositions = new List<Transform>();
private List<Transform> homeFieldsPositions = new List<Transform>();
private Transform pathFields;
private Transform finishFields;
private Transform homeFields;
public GameObject player;
private void Awake()
{
this.gameObject.SetActive(true);
pathFields = this.transform.Find("PathFields");
finishFields = this.transform.Find("FinishFields");
homeFields = this.transform.Find("HomeFields");
int childCountPathFields = pathFields.childCount;
int childCountFinishFields = finishFields.childCount;
int childCountHomeFields = homeFields.childCount;
//Adding the children of the Path Fields game object to list
for (int i = 0; i < childCountPathFields; i++)
{
pathFieldsPositions.Add(pathFields.GetChild(childCountPathFields - 1));
}
//Adding the children of the Finish Fields game object to list
for (int i = 0; i < childCountFinishFields; i++)
{
finishFieldsPositions.Add(finishFields.GetChild(childCountFinishFields - 1));
}
//Adding the children of the Home Fields game object to list
for (int i = 0; i < childCountHomeFields; i++)
{
homeFieldsPositions.Add(homeFields.GetChild(childCountHomeFields - 1));
}
Debug.Log("Finish fields positions count is:" + finishFieldsPositions.Count);
Debug.Log("Path fields positions count is:" + pathFieldsPositions.Count);
Debug.Log("Home fields positions count is:" + homeFieldsPositions.Count);
for (int i = 0; i < homeFieldsPositions.Count; i++)
{
Debug.Log(homeFieldsPositions[i].transform.position);
}
}
}
I saved all child positions of 3 types of fields into Lists of Transform, but for some reaosn, when I want instantiate some game object on positions of items of these 3 lists, all game Objects are always instantiated on a one single component of lists, so all of them are at the same position of one Transform component from the lists.
What am I doing wrong here?
Thanks a lot for the help