- Home /
How can i find the world Position from a Child Object in a List?
Hey guys. I'm trying to build a Tower Defense Game. I have a Prefab including Tiles to build turrets on, a path for enemies and waypoints (Gameobjects) as Childs and when spawning, the waypoints are assigned into a List. Now, for testing, I want to spawn a block on one of the waypoints.
So im getting the highest index in the list but when I try to spawn it there, the block is spawned at the local position, not the world position. Everything i found online states that transform.position is ALWAYS the world position but it doesnt work for me.
void Update()
{
if(Input.GetKeyDown(KeyCode.E))
{
tm.addLand(landprefab);
Generate();
}
if(Input.GetKeyDown(KeyCode.R)) // thats the enemie spawning section.
{
Instantiate(enemie, tm.waypointList[tm.waypointList.Count - 1].transform.position, Quaternion.identity);
}
}
That code is getting the last waypoint in the list and providing its position in world space. Your issue might be when you are storing the waypoints, but that code isn’t visible here. It’s not possible to tell you what is happening with the current info you’ve provided