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 ufukk · Jun 12, 2015 at 08:33 PM · movementmovemove an objectmovescript

Character input key doesnt work

I want to control my character with input key,for example i wanna run my character when i press the w button,for this i add a run animation to my character and i write a simple script code but when i run the project Ethan(my character) doesnt move or doesnt idle,nothing happens,can anyone help?

 public Rigidbody rb;
 public float thrust;
     // Use this for initialization
     void Start () {
         rb = GetComponent<Rigidbody> ();
     }
     
     // Update is called once per frame
     void Update () {
     
         rb.AddForce (transform.forward * thrust);
         if (Input.GetKeyDown ("w")) {
             GetComponent<Animation>().Play("HumanoidRun");
 
         }
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 Mouton · Jun 16, 2015 at 05:28 PM 0
Share

If it doesn't run or neither idle, there may have errors somewhere else. Does the console output anything ?

Did you tried to replace GetComponent().Play("HumanoidRun"); with a debug message ?

Did you tried to do the same in the Update loop in order to be sure that it the instruction is read ?

avatar image ufukk · Jun 21, 2015 at 10:30 AM 0
Share

I tried to replace GetComponent().Play("HumanoidRun"); and got an exception UnityEngine.Component.GetComponent()' cannot be inferred from the usage. Try specifying the type arguments explicitly and i put a debug message in if control and i got this message the main thread can go into if control i cannot achieve this challange help more please

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by alebasco · Jun 12, 2015 at 09:06 PM

GetKeyDown when using a string is looking for a key as named in the Input manager of Unity.

http://docs.unity3d.com/ScriptReference/Input.html

By default, it will be called "Vertical" and is an axis. This is generally how you want to use the input, as an axis.

If you want to avoid the Unity input then you should be checking Input.GetKeyDown(KeyCode.W);

This will tell you the frame that the W key is pressed in. If you want to know if the button is being pressed, then just use GetKey(KeyCode.W)

Comment
Add comment · Show 3 · 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 ufukk · Jun 13, 2015 at 08:46 AM 0
Share

I used if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.W)) { GetComponent<Animation>().Play("HumanoidRun"); } but still nothing happens

avatar image alebasco · Jun 14, 2015 at 10:42 PM 0
Share

Are you using an Animation component (NOT Animator - they are different components!), with an animation named "HumanoidRun"?

avatar image ufukk · Jun 16, 2015 at 04:53 PM 0
Share

Yes I am using animation component and using an animation which is named HumanoidRun but I cannot understand what's wrong help please..

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

move enemy to old position of player 2 Answers

How to make a motorbike turning mechanism? Here is my current movement script that has a very bad turning mechanism. 0 Answers

Move character up and down while animation runs 2 Answers

Slowly move a GameObject on 1 axis, then destroy it. 1 Answer

Objects move on play 3 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