GameObject List and For Loop with OnGUI

I’ve been googling and thinking and I just can’t seem to figure this out.

I have a Window, w: 180 h:385. I am using this as a “radar list”.

I want to get everything tagged “Enemy” and propagate said list. One column, straight down. The window is draggable, but I’d love to throw a scroll in it incase you have so much in your list.

I also do have icons that would be to the left of the gameobject in the lists name.

I know this should be a simple for loop… but I just can’t figure it out :confused:

If anyone can help me, I’d love you forever!

Thanks!

This is what I’ve started with.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class PSK_RadarList : MonoBehaviour {

	public List<GameObject> radarContacts = new List<GameObject>();
	public Rect radarScreen;

	void Start () {
		radarScreen = new Rect(Screen.width *0.86f,Screen.height * 0.01f,180,385);
	}

	void OnGUI(){
		radarScreen = GUI.Window (1, radarScreen, DrawRadarList, "Radar");
	}

	void Update () {

	}

	void DrawRadarList(int WindowID){

		GUI.DragWindow(new Rect(0, 0, 180, 20));
	}
	
}

As I understood, you need to make show of the list of your “Enemy” in a window. I will write you a small example:

 public List<GameObject> radarContacts = new List<GameObject>();
 public Rect radarScreen;

 public Vector2 scrollPosition = Vector2.zero; //add variable for scroll

 void Start() {
  radarScreen = new Rect(Screen.width *0.86f,Screen.height * 0.01f,180,385);
  //You need initialization your List. I initialization on the simple
  GameObject[] tempic = GameObject.FindGameObjectsWithTag("Enemy");
  //Of course, you can to use System.Linq for convert
  radarContacts.Clear();
  for(int i = 0; i < tempic.Length; i++) {
   radarContacts.Add(tempic*);*

}
}
void Update() {
}
void OnGUI() {
//Create your window. Size you know.
radarScreen = GUI.Window (1, radarScreen, DrawRadarList, “Radar”);
}
void DrawRadarList(int WindowID) {
//Create scroll list. For example, 1 line have size 200x60
//About parameters: 1 - rectangle of view, 2 - position scroll, 3 - rectangle of full list
scrollPosition = GUI.BeginScrollView(new Rect(0, 0, radarScreen.width, radarScreen.height), scrollPosition, new Rect(0, 0, radarScreen.width, 60*radarContacts.Count));
for(int i = 0; i < radarContacts.Count; i++) {
//For example, show name object
GUI.Label(new Rect(0, 60i, radarScreen.width, 60), radarContacts.name);*
}
GUI.EndScrollView();
GUI.DragWindow(new Rect(0, 0, 180, 20));
}
I hope that it will help you.