Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by J_Troher · Oct 10, 2014 at 06:10 AM · guigameobjectlistonguiforloop

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 :/

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));
     }
     
 }

 

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by zharik86 · Oct 10, 2014 at 06:55 AM

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[i]);
   }
  }

  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, 60*i, radarScreen.width, 60), radarContacts[i].name);
   }
   GUI.EndScrollView();
   GUI.DragWindow(new Rect(0, 0, 180, 20));
  }

I hope that it will help you.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image J_Troher · Oct 11, 2014 at 01:10 AM 0
Share

With a little modification. I got what I wanted out of it. I made a function that repeats every 5 seconds (a radar ping if you will).

I will need to add a bit to it, handling things leaving and entering it, etc. Since its meant to be active all the time.

But good going thank you! :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

28 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

How to select an Game Object from an Item List 0 Answers

I keep getting an error on my for loop. 1 Answer

How completly remove GUI.Repaint() calls ? 1 Answer

Moving Target Circle 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges