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 NoyesBoy93 · Mar 15, 2013 at 02:14 PM · rtsselectable

How can i select Units for an RTS layout?

This script right here shows that the mouse has clicked said point, but has done nothing with the units. using UnityEngine; using System.Collections;

public class UnitDetection: MonoBehaviour { public GameObject flag; public float distanceToMap = Mathf.Infinity; public GameObject selection; public Vector3 moveToPosition;

 void Awake()
 {
     flag = GameObject.Find("_Flag");
 }
 
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         CastRay();
     }
 }
 
 public void CastRay()
 {
     Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     RaycastHit hit;
     
     if (Physics.Raycast(ray, out hit, distanceToMap))
     {
         SelectableUnit su = hit.transform.GetComponent();
         
         if (su != null && su.unitSide == SelectableUnit.UnitSide.friendly)
         {
             selection = hit.transform.gameObject;
         }
         
         if (su == null)
         {
             moveToPosition = hit.point;
             moveToPosition.y = 0;
             flag.transform.position = moveToPosition;
         }
     }
 }

}

I have a seperate script that tells the units apart from friendly, nuetral, and enemy. So thats out of the way. Im just confused on what to do next. Help?

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 murkantilism · Mar 15, 2013 at 07:58 PM

I'm confused, what are you asking for help with? Selecting any sort of units, or just your own units?

My suggestion would be:

  • OnMouseEnter, create a plane (or cube if your RTS game has different heights) that is re-sized as the user drags it across the screen.

  • OnMouseExit use OnCollisionEnter to find out what the plane collided with. I assume all your units are tagged with "Friendly, Neutral, or Enemy" for the other script, so check for those. If the objects within the plane have any of those tags, add them to a list or dynamic array to keep track of them.

  • Instantiate a small green circle around the units, or make the units brighter, or do something to tell the player they've been selected.

  • Delete the plane

  • Now you've got a bunch of selected units you can give commands to!

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 NoyesBoy93 · Mar 15, 2013 at 08:16 PM 0
Share

Sweet, actually that may work let me try it out first and ill see what happens. Thanks

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

11 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

Related Questions

RTS like Frame on Minimap for user Camera Position with GL not rendering in Multiplayer (MLAPI) 0 Answers

Selecting a selectable using script doesn't seem to work anymore? 1 Answer

RPC Parameter Optimization 1 Answer

RTS Grid and Pathfinding 2 Answers

Best way to simulate Character Controller under Fixed Update? 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