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 Jeronimous · Mar 19, 2015 at 10:41 AM · c#movementbuttonkey

How to push down a button and hold it through script?

I have two buttons, Tab and Shift. I'm using the Tab key as an accelerator.

I want to automate the "keep pressing it" part and make a shortcut to "Lock" it to being pressed down. For that, I tried using Shift.

So when I press shift ONCE, it toggles Tab being pressed down.

But I can't find a way to togle Tab though scripting.

A very important note is that I can't simply make Input.GetAxis("tab") = 1f or just copy the code I'm using on Tab to Shift, because I need to use the Gravity and Sensitivity of the button I set in the InputManager.

Here's the script

 using UnityEngine;
 using System.Collections;
 
 public class ShipThrotle : MonoBehaviour
 {
     public float speed = 100f;
 
     public float maxSpeed = 500f;
     public float acceleration = 0.01f;
 
     public float turnRate = 6005f;
     public float angularDrag = 4f;
 
     public bool isMoving = false;
 
     Rigidbody myRB;
 
 
     // Update is called once per frame
     void Update ()
     {
         myRB = GetComponent<Rigidbody> ();
 
         myRB.mass = acceleration;
         myRB.angularDrag = angularDrag;
 
 
         Vector3 vectorForce = transform.forward * speed * Time.deltaTime;
 
 
 
 
         if(Input.GetAxis ("Throtle") > 0f)
         {
             GetComponent<Rigidbody>().drag = 0f;
             GetComponent<Rigidbody>().AddForce (vectorForce);
             myRB.velocity = Vector3.ClampMagnitude (myRB.velocity, maxSpeed);
         }
         
         if(Input.GetAxis ("Throtle") < 0f)
         {
             if(myRB.velocity.magnitude > Vector3.zero.magnitude)
             {
                 GetComponent<Rigidbody>().drag = (GetComponent<Rigidbody>().drag + 0.01f) * 1.01f;
             }
         }
         //Debug.Log (myRB.velocity);
 
 
 
 
         //
         if(Input.GetButton("RotateLeft"))
         {
             myRB.AddTorque(transform.forward * turnRate * 2 * Time.deltaTime);
         }
 
         if(Input.GetButton("RotateRight"))
         {
             myRB.AddTorque(-transform.forward * turnRate * 2 * Time.deltaTime);
         }
 
 
         //Debug.Log (Input.GetButton("RotateLeft"));
         Debug.Log (myRB.velocity.magnitude + "Meters/Sec");
         //Debug.Log (((myRB.velocity.z / 1000) * 60 * 60).ToString("F2") + "Km/Hour");
 
         //Turn
         float h = Input.GetAxis ("Horizontal") * turnRate * Time.deltaTime;
         float v = Input.GetAxis ("Vertical") * turnRate * Time.deltaTime;
         
         myRB.AddTorque (transform.up * h);
         myRB.AddTorque (-transform.right * v);
 
 
         
     }
 }
 



Could anybody help me, please?

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

20 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

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

Increasing value by one every second, if right arrow is pressed - C# 3 Answers

Key for GUI.Button 2 Answers

How can i do: When the button "play"is pressed, the player can start to move, but if not pressed the player cannot move. 1 Answer

Multiple Cars 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