How can I find the transform location of many game objects instantiated from a prefab? (game screen shots included!)

Hi! I’ve been playing around with the scripting in unity and I’m looking to just print the locations of game objects that are instantiated from a prefab in the game. The game is just a big open field where i can run around and spawn cubes by right clicking! I would like to (just in the debug log) print out the transform location of every cube the player has spawned.

Here’s a fun image of the game: 11901-funwithcubes.png

You see when I press save it does save the player location and then it loads the player at the location it saved… Now im going to do the same with the cubes instantiated in the scene, but of course first i need to print the transform locations of the cubes to the Debug.Log()

Any help would be greatly appreciated! THANKS!!! :smiley:

You need to identify these game objects apart from other game objects. You could tag them all the same, name them all the same, or give them all the same component for example. Based on that attribute, you generate an array of the game objects and cycle through them. For example, if they (and only they) had the same tag, you could:

#pragma strict  

function Update() {

	if (Input.GetKeyDown(KeyCode.A)) {
		var gos = GameObject.FindGameObjectsWithTag("Enemy");
		for (var i = 0; i < gos.Length; i++)
			Debug.Log(gos*.transform.position);*
  • }*
    }
    This will output to the console the position of all the game objects with the “Enemy” tag.