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 Robomaster · Apr 03, 2012 at 10:46 PM · rtsboxselecting

Rts people select

Im trying to help a friend create a RTS game and i want to program it so i can create a box by clicking down on my mouse and dragging it and what ever is in the box gets selected this is what is have so far

using UnityEngine;

using System.Collections;

using System.Collections.Generic;

public class RTStargeting : MonoBehaviour {

public Transform selectedTarget;

void Update(){

 if (Input.GetMouseButtonUp(0)){ // when button clicked...

   GUI.Box(new Rect());
 }


private void SelectTarget(){

 selectedTarget.renderer.material.color = Color.red;

 

 }



private void DeselectTarget(){

 if (selectedTarget){ // if any guy selected, deselect it

   selectedTarget.renderer.material.color = Color.blue;

   selectedTarget = null;

 

     }

 

     }

} i have no idea what to put in the GUI box can anyone help me alter or complete this script so that when i click down and darg my mouse it creates a box and whatever character that are in it get selected

Comment
Add comment · Show 3
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 aldonaletto · Apr 03, 2012 at 11:04 PM 0
Share

@Will467, don't ask people to write scripts for you - that's a recipe for disaster here in UA, and you will only get downvotes. Try something like "could someone indicate a tutorial" or similar things - you may even end with a C# script written by some good soul, or at least with several useful links.

avatar image Robomaster · Apr 03, 2012 at 11:20 PM 0
Share

Oh ok im still new to unity and program$$anonymous$$g i didnt know ill alter my question.

avatar image Robomaster · Apr 03, 2012 at 11:25 PM 0
Share

ok i altered my question, also i wanted to thank you for all your help it is really appreciated

2 Replies

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

Answer by Adamcbrz · Apr 07, 2012 at 04:56 AM

Well you need to find your two points in the world to draw your box. I would probable setup a plane with a collider that represents your ground and raycast from your mouseposition using the camera to ray function ( on phone so can't look up docs ). Then store the raycast hit point into a vector3 on mouse down then while the mouse is down update you box to draw in world space from your starting vector3 to your current mouse position hit point. Once you define that area all you have to do is determine which Targets are in that area.

Hope that helps.

Comment
Add comment · Show 2 · 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 Robomaster · Apr 07, 2012 at 01:01 PM 0
Share

how would i program that i am a newbie at program$$anonymous$$g and i have no idea how i could program that

avatar image yveris · Nov 21, 2012 at 10:46 PM 0
Share

Would you use a ray cast from the selection box, like iterate through each point within the box? I have a function that creates the selection box, but I'm unsure whether to use ray casts or create a box and use a sweep test.

But I assume the sweep test would have have too many collisions once there's many units and impact performance.

avatar image
0

Answer by Malevolent_King · Apr 24, 2012 at 08:10 PM

http://unity3d.com/support/documentation/ScriptReference/Input-mousePosition.html

find mouseposition using raycast

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Click and Drag RTS Mouse selecting script help. 1 Answer

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

Cant select objects using my box-selection script 1 Answer

RTS-Style Selection Square 2 Answers

Unity RayCast Selection 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