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 Qo2770 · Jan 05, 2014 at 06:10 PM · raycastrtsselection

RTS Game: Unit selection through Raycast

I am making an RTS game and, of course, need to be able to select units. I spent 3/4 of today trying to make it work by myself, the other 1/4 of the day I spent following tutorials, but none of them worked. I would just like a hint or a push in the right direction, for I want to accomplish at least a bit by myself.

P.S.: I am not new to programing or Unity3D, I am no noob.

Comment
Add comment · Show 2
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 ncallaway · Jan 05, 2014 at 06:29 PM 0
Share

Perhaps you could give us a little more information on what you've tried so far, and what you mean by "none of them worked"?

Is there a specific concept you're getting stuck on? Code that you implemented that isn't behaving like you expect it to?

avatar image Kiloblargh · Jan 05, 2014 at 07:25 PM 0
Share

I have RTS-style unit selection working in my game using raycasts. So I could help you but as ^ said, you need to post sections of script and/or screenshots showing what you were trying to do and how it is failing.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Kiloblargh · Jan 05, 2014 at 10:08 PM

In the game I'm currently working on, I have a MasterControl script that keeps track of these things (among many others...)

 selectedMover : Unit
 remoteSelectedMover : Unit
 moveTarget : Transform
 remoteMoveTarget : Transform

Every unit has a script on it- and it's the same one script, it's just configurable to be any controllable unit in the game.

The Unit script's TakeClick() function is called from an input script on the main camera that does the ray cast, using a LayerMask set to selectable units only:

 hit.collider.gameObject.GetComponent.<Unit>().TakeClick();

This function checks with the MasterControl script to see if the unit belongs to the player or is an enemy, and if the selectedMover variable is null, the clicked unit, or another unit; and decides based on that what needs to happen next.

The Unit script has a Select() function and a Deselect() function that shows/hides selection graphics FX and plays a short animation and sets its "isSelected" variable to true or false.

I still need to extend what I have to allow group selecting and giving move-attack orders to multiple units at once. Selecting just one at a time is not acceptable for a final game (well, maybe, if you're doing something more XCOM than StarCraft...) but you should probably still start out with selecting one unit at a time with the thought of how to make it work with groups- the devil is in the details. For my game I can replace all my single variables with Lists and won't have to change much else.

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
avatar image
0

Answer by Qo2770 · Feb 01, 2014 at 11:20 AM

Thanks, Sorry that I was not answering but my computer broke down...

Thanks for the help though! I think that is what I was looking for!!

  • Qo2770

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

19 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

Related Questions

Math/Programming Question 4 Answers

Unity RayCast Selection 1 Answer

C# converting Input.Mouseposition.y to to "top" argument of GUI.Box 1 Answer

How to make free area selection(like lasso tool in photoshop) in rts? 2 Answers

Toggling active between objects using a boolean 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