(Solved)GameObject in Array to String

I’m trying to return the name of a GameObject in an Array as a string? In the code below I am creating a button for every GameObject with a certain “Tag” name. I’m trying to get the button to display the name of the GameObject, but I cant figure out how to convert it to a String.

function OnGUI()

EnemyList = GameObject.FindGameObjectsWithTag("Enemy"); 

for (i = 0; i < EnemyList.length; i++){
	if (GUILayout.Button(EnemyList[i].ToString))
	    print (EnemyList[i]);
	}

}

gameObject.name

–Eric

i’ll have to try that next. I got this to work just now.

function OnGUI(){
FriendlyList = GameObject.FindGameObjectsWithTag("Friendly");
EnemyList = GameObject.FindGameObjectsWithTag("Enemy"); 
f=0;
var FNames = new String[FriendlyList.length];
		
	for (var Name : GameObject in FriendlyList)
		FNames[f++] = Name.name;
		for (f = 0; f < FriendlyList.length; f++){
			if (GUILayout.Button(FNames[f]))
				
				Target = FriendlyList[f];
		}

gameObject.name is much better. Thanks :slight_smile: