Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Sep 16, 2019 at 07:00 PM by vanIvan for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by vanIvan · Sep 16, 2019 at 06:21 PM · editorcustom editorproblema

Input problem...

I want to add to my Custom Level Editor a special function : whenever user holds a Shift key (doesn't really matter left or right) he can more accuratly move objects (0.1 per pressing button vs 1). However, this function is not working for me... Maybe you can add your own solution and help me...

 if (Input.GetKey(KeyCode.D))
             {
                 foreach(GameObject t in selection)
                 {
 
                         t.transform.position += new Vector3(1, 0, 0);
 
                 }
             }
             else if (Input.GetKey(KeyCode.W))
             {
                 foreach (GameObject t in selection)
                 {
 
                         t.transform.position += new Vector3(0, 1, 0);
 
                 }
             }
             else if (Input.GetKey(KeyCode.A))
             {
                 foreach (GameObject t in selection)
                 {
 
                         t.transform.position += new Vector3(-1, 0, 0);
 
                 }
             }
             else if (Input.GetKey(KeyCode.S))
             {
                 foreach (GameObject t in selection)
                 {
 
                         t.transform.position += new Vector3(0, -1, 0);
 
                 }
             }
             else if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift))
             {
                 if (Input.GetKey(KeyCode.D))
                 {
                     foreach (GameObject t in selection)
                     {
 
                         t.transform.position += new Vector3(0.1f, 0, 0);
 
                     }
                 }
                 else if (Input.GetKey(KeyCode.W))
                 {
                     foreach (GameObject t in selection)
                     {
 
                         t.transform.position += new Vector3(0, 0.1f, 0);
 
                     }
                 }
                 else if (Input.GetKey(KeyCode.A))
                 {
                     foreach (GameObject t in selection)
                     {
 
                         t.transform.position += new Vector3(-0.1f, 0, 0);
 
                     }
                 }
                 else if (Input.GetKey(KeyCode.S))
                 {
                     foreach (GameObject t in selection)
                     {
 
                         t.transform.position += new Vector3(0, -0.1f, 0);
 
                     }
                 }
             }

Comment
Add comment · Show 1
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 vanIvan · Sep 16, 2019 at 06:23 PM 0
Share

*Array "selection" is a holder of all objects, that were selected via special script and placed into a list of objects.

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by vanIvan · Sep 16, 2019 at 06:59 PM

So I figure it out by my own way : I added a new boolean called "shiftPressed" and check if Right or Left shift were pressed, than

 shiftPressed = true;

And when user release one of this buttons:

 shiftPressed = false;

And I move all my objects in selection depending on shiftPressed bool...

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 Hellium · Sep 16, 2019 at 06:30 PM

What a lot of code duplication....

 float step = (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
     ? 0.1f : 1f;
         
 if (Input.GetKey(KeyCode.D))    MoveSelection( Vector3.right, step );
 if (Input.GetKey(KeyCode.W))    MoveSelection( Vector3.up, step );
 if (Input.GetKey(KeyCode.A))    MoveSelection( Vector3.left, step );
 if (Input.GetKey(KeyCode.S))    MoveSelection( Vector3.down, step );

 // ...

 private void MoveSelection( Vector3 direction, float step )
 {
     foreach (GameObject t in selection)
         t.transform.position += direction * step;
 }
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 vanIvan · Sep 16, 2019 at 06:41 PM 0
Share

Nope, it still doesn't work, however if I will push shift+A at one time it works. But I want to be able to hold shift, press button and than object should move at 0.1 point. If shift key is not pressed, it should move at 1 point...

avatar image Hellium vanIvan · Sep 16, 2019 at 07:18 PM 0
Share

The code works perfectly fine here. You may have changed Input.Get$$anonymous$$ey by Input.Get$$anonymous$$eyDown somewhere.

Follow this Question

Answers Answers and Comments

148 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 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 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 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 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 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 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 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

Custom editor script for folders? 1 Answer

How do I access the "Edit Collider" function from the inspector in a custom editor. 1 Answer

Custom Editor applies changes to every instance of the component/class its for, how do I fix this to modify the target instance component only? 0 Answers

EditorWindow: How to Serialize variables after PLay 1 Answer

How to allocate layout region inside the inspector? 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