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 John Essy · May 10, 2011 at 03:00 PM · animationloop

Could some wise person please help with this animation problem

Hi there and thanks for looking. The problem i am having is i want this script to play like this

  1. when i dont press anything it animates "idle"
  2. when i press "a" or "d" it animtes and loops "run"
  3. Whe i let go it stops looping "run" and Animates and loops idle.

Here is my code below also could someone please tell me how to format my code for these forums

function Awake() { animation["Idle"].layer = 0; animation["Run"].layer = 1; animation["Jump"].layer = 2; }

var wrapMode : WrapMode;

function Update() { if (Input.GetKey("d")) { animation["Run"].layer = 1; animation["Run"].wrapMode = wrapMode.Loop; } else if (Input.GetKeyUp("d")) { animation["Idle"].layer = 0; animation["Idle"].wrapMode = wrapMode.Loop; } else if (Input.GetKey("a")) { animation["Run"].layer = 1; animation["Run"].wrapMode = wrapMode.Loop; } else if (Input.GetKeyUp("a")){ animation["Idle"].layer = 0; animation["Idle"].wrapMode = wrapMode.Loop; }

if (Input.GetButtonDown("Jump")) { animation.CrossFade("Jump"); } else{ animation.CrossFade("Idle"); } }

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 DaveA · May 10, 2011 at 03:18 PM 0
Share

Hit the 'edit' link, select what you want formatted as code, hit the 010/101 button along the top of the editing window.

1 Reply

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

Answer by ShadowBroker · May 11, 2011 at 02:00 PM

The problem is, that Run is on layer 1 and idle on 0, so Run beats Idle. You also don't have to set the layers and wrapModes always again. Once set, it keeps until the game is stopped. Also, you could try to stop the run animation if the key is lowered. I think of something in a way like this:

 if (Input.GetKeyUp("a")){
      animation.Stop("Run");
}

This should be everything you need.

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

Won't loop animation (solved!) 2 Answers

how to stop animation loop? 1 Answer

Unity does not recognize reload animation for gun 1 Answer

Add animation curve through script 2 Answers

Unity3D AI using animations 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