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 1337GameDev · Dec 24, 2011 at 04:32 AM · mobilertsselectionboxmarquee

Create selection box by double tapping then dragging? (android mobile)(cnc style)(image embedded)

I am curious how to make a box (visually show selection while dragging) to select units to give orders to, like command and conquer does?

Like this game uses: alt text

I also would prefer fill, as it is user friendly to see the insides of the selection box.

I supposes i could do raycast draw, but i know it could be used to represent the box, but how do i find each object inside it? Make a rectangle and use the "contains method"? How do i account for the camera being at an odd angle or rotation? Would i be able to store all objects inside an array of gameobjects, then iterate through them? How would i do the fill, even if my camera is at odd angles?

I don't know the best way to do this. Can anybody give me examples or steer me in the right direction?

I did find this post: selectionbox example

But it didnt seem to really help me.

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
1
Best Answer

Answer by 1337GameDev · Aug 26, 2013 at 02:25 AM

I did eventually figure this out. I just created a touch handler script to detect the states of the selection box: start, active, reset, selectUnitsWithSelectionBox.

I used a semi transparent guiTexture for the selection box, and kept track of the starting point, and then stretched the box based on the current touch and the starting point.

Then i handled moving the box if i cancelled the selection, or if i selected objects.

Then for object selection, i would report the positions of all gameobjects that are being rendered (using a list created by the isRendered flag), and select the ones that have screen coordinates in the guiTexture.

I used:

 if(selectionBoxRectangle.Contains( MainActiveCamera.WorldToScreenPoint(currentObjToTest.transform.position) ))

This seemed to work fine.

For selection, I would just create a prefab that has a plane that billboards to the active camera, and is scaled to be large enough to surround the largest bounds of the shop. I did this using bounds.Encapsulate, and got the largest bounds from the center of the unit.

The prefabs also displays contextual data, such as health bars, shield, and armor of the prefab's parent.

Hope this will help somebody in the future who stumbles across this post.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Cant select objects using my box-selection script 1 Answer

Avoid iterating through all gameobjects to select units using marquee selection box (selection box is already created, just have to be efficient) 2 Answers

Creating a cube as a selection box and detecting all collided objects inside of it. 2 Answers

unit selection issue 0 Answers

RTS Style Selection system (How to control one unit and not the others) 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