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
2
Question by Kreg Neg · Jun 21, 2013 at 04:17 PM · guitag

Pointers to Show Off-Screen Enemies

I have made this script to create a GUI Texture at every Enemy (/every tag you tell it to) and it works great so far but now I want to add an off screen indicator to show where enemies you can't see are. (sort of like this)

P.S- I dont need a real script... just "pointers" on how to do it

-heres my code-

 var multiplier : float;
 var style : GUIStyle;
 private var list : String;
 var range : int;
 var TargetTags : String[];
 var TargetTexture : Texture[];
 
 function OnGUI ()
 {
     for(var t = 0; t < TargetTags.Length; t ++)
     {
         var pointers : GameObject[];
         pointers = GameObject.FindGameObjectsWithTag(TargetTags[t]);
         
         list += "------------------ \n" + TargetTags[t] + "\n ------------------ \n";
         
         for(var pointer in pointers)
         {
             var dist = Vector3.Distance(transform.position,pointer.transform.position);
             if(dist < range)
             {
                 if(pointer.renderer.isVisible)
                 {
                     var size = multiplier / dist;
                     var rect : Vector3 = camera.WorldToScreenPoint(pointer.transform.position);
                     GUI.DrawTexture(Rect(rect.x -size/2,Screen.height - rect.y - size/2,size,size),TargetTexture[t],ScaleMode.StretchToFill,true,10.0f);
                 }
                 
                 list += pointer.name + "\n";
             }
         }
     }
     GUILayout.Box(list);
     list = "";
 }
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

Answer by trvr · Jun 21, 2013 at 04:31 PM

Try using something like this:

 var allEnemies = GameObject.FindGameObjectsWithTag("Enemy");

to find all game objects with a certain tag, then use:

 transform.LookAt

to get the arrows to automagically face the right way. As for only showing objects off camera, have a look at Renderer.OnBecameInvisible. Looks like that will do exactly what you need.

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 Kreg Neg · Jun 21, 2013 at 06:58 PM 0
Share

Sorry...It seems I wasn't very clear before. I want a GUI Texture to point to the offscreen objects not have myself turn to face the object. The allEnemies and OnBecameInvisible seem okay for what I want but I need something to find which direction the object is in- maybe using Vector3.Dot?

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

16 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

Related Questions

how can i get GUI.Button presse(or down not click) 3 Answers

Where do I assign GUI scripts? 1 Answer

Intro GUI Text Script... 3 Answers

GUI Resolution Ajust 1 Answer

Load an image from www and save it for offline use 0 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