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 /
avatar image
0
Question by pax · Jun 05, 2011 at 09:13 AM · getkey

GetKey is not working...

Hi Guyz... I am new to unity3d. I have simple question In following code GetKey is not at all working....

 void Update () 
 {
     if(Input.GetKey (KeyCode.Z))
     transform.Translate (speed, 0, 0);
      }

Do I need to register 'Z' key somewhere in setting or am I missing something????

-pax

Comment
Add comment · Show 2
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 Bunny83 · Jun 05, 2011 at 01:13 PM 0
Share

No, that should work. $$anonymous$$ake sure that you attached the script to the right GO and no other script modifies the position. Also check your speed variable. $$anonymous$$aybe your problem is that you didn't focus the game window/tab. Try to click once into the window after entering run-mode.

avatar image Lanc · Apr 03, 2012 at 08:23 AM 0
Share

For me it's not working. Defenitly some problem in Get$$anonymous$$ey for my $$anonymous$$ac OS X Leon - Input.characterinput is ok, but Input.Get$$anonymous$$ey() - not working with keyboard symbols, only with numbers. WASD also not working for FPS controller. I'm mad about it.

5 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Shrimpy · Jun 05, 2011 at 10:04 AM

try this instead:

 if(Input.GetKey("z"))


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

Answer by MacMac098 · Jun 05, 2011 at 01:59 PM

 In JavaScript

 var moveSpeed : float = 10;

 function Update () 

 {
 if((Input.GetKey("z"))
  {
  transform.Translate (moveSpeed, 0, 0);
  }
 }
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
-1

Answer by frederikedel · Jul 18, 2020 at 01:02 PM

@ Shrimpy's Answer is completely right: The letter buttons on your keyboard you get with quotation marks "z". If you use other Input devices, you have to register the buttons in the Input Manager, try searching for a tutorial if you dont understand it.

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 Hellium · Jul 18, 2020 at 01:36 PM 0
Share

Z is not a Keycode

What is this then??

https://docs.unity3d.com/ScriptReference/KeyCode.Z.html

avatar image frederikedel Hellium · Jul 19, 2020 at 12:28 PM 0
Share

$$anonymous$$aybe thats also possible but apparently its not working. "z" works perfectly fine.

avatar image
0

Answer by Yamilla · Jul 28, 2013 at 03:46 PM

Did you define "speed" before the "Update" loop? Did you put the Script on the right GameObject?

There are 2 things you can do. Either you can drag the Script ON the Object you want to Translate, or you add something to it. If you take the second option, do it like this:

 using UnityEngine;
 using System.Collections;

 public class Translate : MonoBehaviour {
     public GameObject whatever;
     public float speed = 10.0f;

     void Update() {
         WiiUGamePad Winp = WiiUInputGamePad();

         if (Winp.GetButtonDown(WiiUGamePadButton.ButtonA)) {
             whatever.transform.Translate(speed,0,0);
         }
     }
 }

I hope you won't get confused about the the Wii U stuff, but I've typed it over from when I was trying to figure out the Wii U Input System (and this one is correct, by the way).

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 BreadMachine · Jul 18, 2020 at 09:54 AM

(Input.GetKeyDown(KeyCode.Z)){

make sure to have { and at the end and close it }

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 Namey5 · Jul 18, 2020 at 11:05 AM 0
Share

Brackets aren't necessary if the conditional only affects one line. These three if-statements are identical; you only need surrounding braces when multiple lines are affected by the condition.

 if (condition) DoSomething ();
 
 if (condition)
     DoSomething ();
 
 if (condition)
 {
     DoSomething ();
 }

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

11 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

Related Questions

Play Animation With GetKey 1 Answer

How to keep object rotating when key is pressed once 2 Answers

Input.GetKey not working 1 Answer

Converting a string to keycode 3 Answers

Stop animation after .5 seconds? 2 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