I made a list of Tiles that are instantiated. I want to retrieve a location of objects later in a new function. I tried using transform.position and GetComponent().transform.position but I keep getting NullReferenceException: Object reference not set to an instance of an object. This line is where the error occurs:
Debug.Log ("Tiles: " + tiles*.GetComponent().transform.position);*
-
public List tiles = new List();*
-
public int gridWidth;*
-
public int gridHeight;*
-
public GameObject tilePrefab;*
-
// Use this for initialization*
-
void Start () {*
-
for (int y = 0; y < gridHeight; y++) {*
-
for (int x = 0; x < gridWidth; x++)*
-
{*
-
GameObject g = Instantiate(tilePrefab, new Vector3(x,y,1), Quaternion.identity) as GameObject;*
-
g.transform.parent = gameObject.transform;*
-
tiles.Add(g.GetComponent<Tile>());*
-
}*
-
}*
-
gameObject.transform.position = new Vector3 (-3.5f, -3.5f, 1);*
-
}*
-
public void CheckTiles(){*
-
for (int i = 0; i < tiles.Count; i++) { *
-
Debug.Log ("Tiles Count: " +tiles.Count);*
_ Debug.Log ("Tiles: " + tiles*.GetComponent().transform.position);_
_ Debug.Log("tiles : " + tiles.transform.position);
}
}*_