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 josif · Jun 20, 2010 at 01:48 PM · animationrunwalk

walk to run animation

how can i make this code that when i press T its switches the animation to run and when i press T again it changes back the animation to walk this is what i got now and if you can help me that will be great if your confused just comment

animation.wrapMode = WrapMode.Loop;

animation["jump"].wrapMode = WrapMode.Clamp; animation["shoot"].wrapMode = WrapMode.Clamp; animation["grab"].wrapMode = WrapMode.Clamp;

animation["idle"].layer = -1; animation["walk"].layer = -1; animation["run"].layer = -1;

animation.Stop();

function Update () { if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1) animation.CrossFade("walk"); else animation.CrossFade("idle"); if(Input.GetKeyDown("t")) animation.CrossFade("run");

 if (Input.GetButtonDown ("Jump"))
     animation.CrossFade("jump");

 if (Input.GetButtonDown ("grab"))
     animation.CrossFadeQueued("grab", 0.08, QueueMode.PlayNow);

 if (Input.GetButtonDown ("Fire1"))
     animation.CrossFadeQueued("shoot", 0.3, QueueMode.PlayNow);

}

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by AnaRhisT · Jun 20, 2010 at 01:53 PM

    if(Input.GetKeyDown("t"){
    if(animation.CrossFade == "run"){
       animation.CrossFade("walk");
    }
    else{
    animation.CrossFade("run");
    }
  }
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 Tetrad · Jun 20, 2010 at 05:01 PM

if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
    animation.CrossFade("walk");
else
    animation.CrossFade("idle");

You need to change this code. Basically you're crossfading to "idle" every frame that you're not moving and not pressing down on T.

You need to add another variable to set the "idle but running" state when you press T so you're not crossfading to idle every frame.

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

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

No one has followed this question yet.

Related Questions

Locomotion System (By Rune Skovbo Johansen) 1 Answer

why my Animation "Run" wont work 1 Answer

Lerpz ThirdPersonPlayerAnimation bug - running at walking speed 1 Answer

How do i make my player go from walk animation to run animation using blend trees? 2 Answers

Speed of animation transitoins 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