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
1
Question by mido557 · Dec 16, 2012 at 11:35 PM · guiloopobjectsformany

Drawing GUI onto multiple objects using for loops?

As the title may suggest, the problem I am currently having is this: I can't find a way to make GUI draw onto multiple objects. I tried what I have below, but it didn't work, probably because I'm not referencing the "enemies" object. I have no idea where I would be able to put the "enemies" object, since putting it behind the GUI.DrawTexture gives me a "Null Reference Exception" error.

     for(var enemies : GameObject in Enemies) {
         if(LockedOn == false) {
     //    GUI.DrawTexture(Rect (screenPos.x-10, screenPos.y-12, 25, 25), EnemyOutline);
         }
     }
 
Comment
Add comment · Show 1
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 mido557 · Dec 18, 2012 at 12:54 PM 0
Share

Shameless bump :)

1 Reply

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

Answer by PAEvenson · Dec 18, 2012 at 01:51 PM

Maybe you are looking for something like this? Have not tested...but should point you in the right direction.

 var enemyScreenPos = Camera.current.WorldToScreenPoint(enemies.transform.position);
         GUI.DrawTexture(Rect (enemyScreenPos.x-10, enemyScreenPos.y-12, 25, 25), EnemyOutline);
Comment
Add comment · Show 11 · 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 mido557 · Dec 18, 2012 at 05:03 PM 0
Share

God I am stupid.....I forgot that my screenPos was referring to the target, not the entire group of enemies.... With a few tweaks it worked, thanks alot :)

avatar image mido557 · Dec 18, 2012 at 05:41 PM 0
Share

If anybody is wondering, this is the changed code, it might help you in your game :D Special thanks to @PAEvenson :) I added a few comments so that you arent confused.

     for(var enemies : GameObject in Enemies) {
     if(enemies != null) {
         if(enemies.renderer.isVisible != false) {
 //if enemies are visible
             if(LockedOn == false) {
 //if we are locked on
         var enemyScreenPos = Camera.current.WorldToScreenPoint(enemies.transform.position);
         enemyScreenPos.y = Screen.height - enemyScreenPos.y;
         GUI.DrawTexture(Rect (enemyScreenPos.x-10, enemyScreenPos.y-12, 25, 25), EnemyOutline);
 
             }
         }
     }
 }
avatar image PAEvenson · Dec 18, 2012 at 07:56 PM 1
Share

woot, thanks

avatar image mido557 · Dec 19, 2012 at 01:22 AM 1
Share

Thnx, Clunk47 :)

avatar image mido557 · Dec 19, 2012 at 07:32 AM 1
Share

Its fine, I just remembered that in the old Answers, code wouldn't display properly(It would come out as a jumble of code, not neatly formatted). At least they fixed it now :D I wouldn't $$anonymous$$d some people being slightly mean towards me, I too would get annoyed if someone didn't know how to post a question properly. That still doesn't give them the right to be arrogant d**k heads though :)

Show more comments

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

12 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

Related Questions

NullReferenceException in for-loop 0 Answers

Change Button GUIStyle on Click 1 Answer

Using for ... var ... in loop to access variable. 1 Answer

How can I make my for loop "reset" if my array contains an value? 5 Answers

Creating Dropdown GUI 1 Answer


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