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 LikeShiSui · Nov 25, 2014 at 10:47 PM · javascriptmechanim

How to Make my Character Run?

Hi, I'm using MECHANIM and I'm having some issues. Essentially, when I press LeftShift, I want to be able to toggle the boolean "IsRunning" (my running animation boolean in MECHANIM) to true, in the else statement set it to false. Buuuut, of course, since I have no idea what I'm doing quite yet, I need your help. This is what I got:

     //SPRINTING
     if(controller.velocity.magnitude > 0 && Input.GetKey(KeyCode.LeftShift))
     {
         theAnimator.SetBool("IsRunning", true);
     }
     else
     {
         theAnimator.SetBool("IsRunning", false);
     }


Just to let you know, I did this at the beginning of the script:

var theAnimator : Animator;

Well that's about it, hopefully you can help me out on this one!

(NOTE: The script gives NO errors, but when I press LeftShift, nothing happens)

Comment
Add comment · Show 1
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 LikeShiSui · Nov 25, 2014 at 11:00 PM 0
Share

Hey, I put some logs in there, and it wasn't reading any output onto the console..weird.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by FrostyNomad · Nov 26, 2014 at 12:43 AM

You may not be getting the Animator object. Your script should look something like this:

 var theAnimator : Animator;

 function Start() {
     theAnimator = gameObject.GetComponent("Animator");
 }

 function Update() {
     if(controller.velocity.magnitude > 0 && Input.GetKey(KeyCode.LeftShift))
     {
         theAnimator.SetBool("IsRunning", true);
         Debug.Log("IsRunning is set to true");
     }
     else
     {
         theAnimator.SetBool("IsRunning", false);
         Debug.Log("IsRunning is set to false");
     }
 }

Also realize that Update is called each frame so, unless the shift key is being held down, IsRunning will be set back to false.

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 LikeShiSui · Nov 26, 2014 at 03:25 AM 0
Share

Hi, I made a new script and pasted that in there, but it still does not work. I through some Debug.Log() statements and nothing was appearing in the console. Have any idea?

avatar image FrostyNomad · Nov 26, 2014 at 03:25 PM 0
Share

I updated my answer to include a couple Debug.Log statements. Checklist: 1. $$anonymous$$ake sure your script builds. 2. $$anonymous$$ake sure you're attaching the script to a GameObject in your scene 3. $$anonymous$$ake sure you have your Console filter toggles set http://i.imgur.com/0XhVtF9.gif

avatar image LikeShiSui · Nov 26, 2014 at 03:48 PM 0
Share

Hey - I followed your instructions and it worked perfectly. Thank you so much for your help. $$anonymous$$udos!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Help Needed! expecting (, found 'Chop'. 1 Answer

Move the Object to Camera respective. 1 Answer

Why is my Experience Script not working? 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Disabling all renderers in Hierarchy 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