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 /
  • Help Room /
avatar image
0
Question by hemingso · Mar 29, 2016 at 03:19 PM · keyboarddocumentation

A relatively simple question of what two unity functions are called

I tried to use code found in the Unity community to turn of certain keyboard buttons, do an action which would conflict with the keyboard input which should be turned off while this conflicting action (movement) is done and turned back on afterwards, the relevant code looks as I found it before I tried to figure out how to make it work. The part that does not function is the word "key" in the third line. I guess the solution is that key should be removed and replaced by some function which takes a parameter as shown and what it does is to disable the relevant keyboard key as defined when the function is called, and a nearly identical method just with another name to undisable the same keyboard key. If this is correct the only information I need is what the functions are called which should be possible to look up in the documentation (look below).

If relevant most of this code is taken from a forum post written by AngryAnt, but it does not function as it stands.

void DisableKey(KeyCode key) {

     if (Event.current.keyCode == key (Event.current.type == EventType.KeyUp || Event.current.type == EventType.KeyDown))
     {
         Event.current.Use();
     }
 }

void Somemethod() {

     DisableKey(KeyCode.A);
     DisableKey(KeyCode.D);
     DisableKey(KeyCode.W);
     DisableKey(KeyCode.S);

}

The main problem is that when I started using Unity I could write for example "transform" mark it and press control + ' and get to a table with possible documentation where the top documentation almost always led to a description of the component with all possible functions and similar which could follow for example "transform." where I could take a closer look on one or more of them and get a usually pretty good description of what the function does and not least what it is called as name. Now control + ' has no effect at all in a script and if I open the documentation and searches for it manually I always get only irrelevant results compared to what I was looking for and the documentation I just described is not among any of the results, not even "transform" which I am quite sure I searched and found that documentation when I started using Unity has this documentation among the alternatives now which means the documentation is completely useless as the situation is now. If someone could tell me how to get the documentation to function as I earlier have used it myself and is used in the tutorals in Unity for the future, it is more likely than unlikely that I can find the answer to this question myself, but if someone has a good answer I will appreciate that answer too, thanks anyway.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · Mar 29, 2016 at 05:04 PM

Maybe you should break this into smaller Qs.

The "intellisense" feature is known to fall off sometimes. There are Answered Qs here about how to get it working again.

I think you want to know whether DisableKey is a Unity function, or if it's been renamed? I think another short Q (with DisableKey) in the title, might be better for that. BUT:

DisableKey is just a very strange function written by this angryAnt person, as a joke (whenever someone starts with "I suppose you could...".) Since it's written out, you 100% know it's not in Unity (that's just basic programming, which you can learn from any book.)

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 hemingso · Apr 07, 2016 at 11:38 AM 0
Share

In the Unity documentation I just oversaw an option switching between $$anonymous$$anual and Scripting and after switching to Scripting the documentation functions as it should. I can't remember to have to do that earlier but it is no problem, the ctr + ' does still not function, but I can search manually no problem, and just a very short question, does it exist unity functions which turn off one or more keyboard buttons either activate and deactivate, or for some time, or do I have to write them myself, and the code "EventType.$$anonymous$$eyUp" and "EventType.$$anonymous$$eyDown", is it correct that this code is part of Unity code which do something when a button is pressed and when it is released and not part of AngryAnt's joke such that it is possible to use this code in a selfcreated function in Unity. If wanted I can post a similar question as a new and short question without the first part of this question.

avatar image
0

Answer by hemingso · Apr 15, 2016 at 06:24 PM

Ok I tried to make my own function using EventType.Ignore to ignore certain keyboard buttons, but I missed some details to get it to work.

if ((Input.GetKeyDown(KeyCode.LeftArrow)) || (Input.GetKeyDown(KeyCode.RightArrow)) || (Input.GetKeyDown(KeyCode.UpArrow)) || (Input.GetKeyDown(KeyCode.DownArrow)) || (Input.GetKeyUp(KeyCode.LeftArrow)) || (Input.GetKeyUp(KeyCode.RightArrow)) || (Input.GetKeyUp(KeyCode.UpArrow)) || (Input.GetKeyUp(KeyCode.DownArrow)) || (Input.GetKeyDown(KeyCode.A)) || (Input.GetKeyDown(KeyCode.D)) || (Input.GetKeyDown(KeyCode.W)) || (Input.GetKeyDown(KeyCode.S)) || (Input.GetKeyUp(KeyCode.A)) || (Input.GetKeyUp(KeyCode.D)) || (Input.GetKeyUp(KeyCode.W)) || (Input.GetKeyUp(KeyCode.S))) {

             EventType.Ignore;

What I want to do is to use code like

float moveHorizontal = Input.GetAxis("Horizontal");

     float moveVertical = Input.GetAxis("Vertical");
     Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

     Vector3 newVelocity = new Vector3(movement.x * speed + movement.x * moveDirection, 0f, movement.z * speed);
     GetComponent<Rigidbody>().velocity = newVelocity;

which increases the speed of the player ship when it hits something (in addition to some strange behaviour which includes not preventing the player ship from overlapping the enemies from the code (movement.x*moveDirection)) together with the code

public IEnumerator MoveRight(int moveDuration) {

     turbulenceDirection += turbulenceSpeeds;
     while (turbulenceDuration > 0)
             (the new code is placed here)
     {
         yield return new WaitForSeconds(1f);
         turbulenceDuration--;
     }
     turbulenceDirection = 0.0f;
 }

What I want to do is to turn off listening to the same buttons as the program listens to for normal movement such that the program no longer listens to those buttons, and the program can then get input from another source as in (transform.right*speed). Normally getting input to movement from two different sources will get the program to crash, but I try to turn off listening to all the same buttuns as Vertical and Horizontal uses and then no input is given to the program for movement from that part of the program and it get no conflict with adding a (transform.right*speed) and (-transform.right*speed) when the program is not listening to normal movement, performing the alternative movement, stop executing the alternative movement and then start listening to normal movement again.

If the main thought of how I think Unity functions regarding to why the program crashes when two different input is used for the same movement is correct and how it is possible to only use one of the two inputs in each frame please confirm and tell me what code is missing to get it to work, if I have misunderstood something of how Unity functions in this situation please tell me how it should be done. Most likely the only change I have to do is changing EventType.Ignore into one or two lines of code. Please explain the last details. If relevant I have tried to get the game behavior of pushing the player ship to the left or right (depending on which side of the enemy the player ship hits of the two possibilities left and right) instead of actually overlapping an enemy when the player ship touches an enemy (which conflicts with the normal movement), for several months or something, and it will be very satisfying when I finally get it to work, and I am quite sure the correct solution is to turn off listening to the normal movement use transform.right*speed as alternative movement turn off alternative movement and start listening to normal movement again. Thank you.

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

What is the correct way to learn unity scripting ? 2 Answers

I am using NOrmcore for Multiplayer, and I was wondering if there is any documentation on making a login-password system? 1 Answer

Keyboard input line has a white background with a white font, can I change colors? 2 Answers

How to create a menu with 2 keyboard cursors? 0 Answers

Handle keyboard keys beyond KeyCode 0 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