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 TustinJimberlake · May 14, 2016 at 02:12 AM · inputupdategetkeydowngetkey

GetKeyDown Not Functioning When Two Unrelated GetKeys are True

So I am working on a game in which you can move around and cast abilities. How it's setup is that the character has a PlayerControls script, where the user can input various control schemes to their liking. Another script, Fireball uses these control inputs to determine when the ability should be cast when a button is hit. In the PlayerControls script, if statements with Inputs determine when the character should stand still, move left, move right, and jump, and sends that information to a completely separate script called PlayerMove, which just moves the character based on the input. The thing you need to understand is that PlayerMove and Fireball are completely separated, and should have no interactions whatsoever. Furthermore, the abilities cast perfectly when the character is standing still, moving left, moving right, with or without jumping, however it doesn't even register a button press when the user inputs the left and right command at the same time.

 public class Fireball : PlayerAbility {
 
     [SerializeField]
     [Range(0f, 100f)]
     private float speed = 10f;
     [SerializeField]
     private bool accelerate = true;
     [SerializeField]
     [Range(0f, 10f)]
     private float duration = 0f;
 
     private int flip = 1;
 
     private ConstantForce2D myForce;
 
     // Use this for initialization
     void Start () {
         myForce = GetComponent<ConstantForce2D>();
 
         if (GameObject.Find("Player"))
         {
             if (GameObject.Find ("Player").transform.Find ("AbiltityPoint").position.x - GameObject.Find ("Player").transform.position.x < 0) {
                 flip = -1;
             } else {
                 flip = 1;
             }
             if (flip == 0)
                 flip = 1;
         }
 
         Destroy(gameObject, duration * 40 * Time.fixedDeltaTime);
     }
     
     // Update is called once per frame
     void Update () {
         if (accelerate)
         {
             myForce.force = new Vector3(speed * flip, 0f, 0f);
         }
         else
         {
             myForce.force = Vector3.zero;
             GetComponent<Rigidbody2D>().velocity = new Vector3(speed * flip, 0f, 0f);
         }
     }
 }


In PlayerControls:

 float HorizontalMovement()
     {
         if (Input.GetKey(left) && !Input.GetKey(right)) 
         {
             return -1f;
         }
         else if (Input.GetKey(right) && !Input.GetKey(left))
         {
             return 1f;
         }
         else if (Input.GetKey(right) && Input.GetKey(left))
         {
             return 0f;
         }
         else
         {
             return 0f;
         }
     }
 

Anyone have any idea what's going on here? Thanks.

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

0 Replies

· Add your reply
  • Sort: 

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

57 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

Related Questions

GetKeyUp does not get called sometimes. 1 Answer

What is the difference between Getkey and Getkeydown (C#) 1 Answer

How can I simulate the smoothness of the Input.GetAxis? 0 Answers

GetKeyUp fires on too many frames 3 Answers

Keyboards Input not working 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