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 growling_egg · Jul 22, 2013 at 10:51 PM · colliderselectionhighlightstrategy

How to tell if something ISN'T clicked on?

So I'm working on an RTS, and I have a JS script that highlights any unit I click on. It works great, I can immediately see stats, controls, etc. for whichever unit I pick. The only problem is, when I want to pick a different unit, the first unit I clicked on remains highlighted.

I'm solid enough with my JavaScript (and with searching unityAnswers) to know if I at least had an idea of how to do it, the code would come in time, but I'm basically at a loss for where to start.

I considered using one tag for units and one for the ground, so when you click the ground the unit un-highlights, but then if I switch from one unit immediately to another, the first one would remain highlighted.

If it helps, my highlight system is based on a line renderer that is added via script when the unit's collider is clicked on. I simply need a way to remove the line renderer when the player clicks on anything that isn't that specific unit's collider. Any thoughts? Hopefully the solution is simple, and I've simply way overthought this :)

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

2 Replies

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

Answer by Jamora · Jul 22, 2013 at 11:04 PM

I would approach this by creating an interface IClickable for each object that can be clicked and keep a List or an Array in a manager somewhere. Whenever anything IClickable is clicked, it's added to that list and a line renderer is added. and whenever a highlighting removal operation (in this case, another click) is performed, it is removed from the list, alongside all the required operations, such as removing the line renderer.

Because it seems you only need one highlighted unit at any given time, a simple variable might be sufficient, but this construct supports mulitiple highlights aswell.

Comment
Add comment · Show 3 · 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 growling_egg · Jul 23, 2013 at 12:06 AM 0
Share

I'll keep those ideas in $$anonymous$$d. I haven't heard of the IClickable interface, is that your own term Jamora? I agree with you guys, an array to keep track of which unit is selected at one time seems like the most logical method. And yeah, if I decide to implement a multi-select sort of function later, it would still work. Arrays, unfortunately, are something I'm not very well-practiced with, but it won't be the first time I've done a little online research. I'll give it a try and let you know how it works out.

avatar image Jamora · Jul 23, 2013 at 12:38 AM 0
Share

If you aren't familiar with the term interface, you should look into it at some point. The C# Program$$anonymous$$g Guide gives an explanation on how to use them, they're pretty much the same in UnityScript, except ins$$anonymous$$d of : you use implements

avatar image growling_egg · Jul 23, 2013 at 02:51 AM 0
Share

Found this in my research, if anyone else finds themselves trying to solve a similar issue, this guide explains it pretty well.

http://wiki.unity3d.com/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use?

Thanks for your help, guys.

avatar image
0

Answer by fransh · Jul 22, 2013 at 11:12 PM

A really simple way would be : Clear the entire selection list, or what ever you use to keep track of the current selection, when ever a input from the selection key is registered.

If the player happened to click on the same unit again (so it should not leave the selection at all in this exceptional case), it will simply be re-selected again because that function that caused it to be selected in the first time, is called again and the player never notices a thing in that situation.

Comment
Add comment · 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

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

18 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

Related Questions

Unity Editor style selection in game 1 Answer

Virtual Reality collider help 0 Answers

Internal collisions 1 Answer

Box Selection 0 Answers

How to highlight the borders of an object 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