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 oShadowkun · Sep 08, 2012 at 12:01 AM · animationfpsrpgsword

Override animation with another

Hello, Thanks for viewing my question. I've been using Unity3D for 2 days, never scripted with javascript. I have 5 animations. Sword idle, Sword run, Sword run side, Sword attack, and Sword attack rightside. and the movement animations activate when you move horizontally, or vertically. The problem being, I can't use my sword attack or sword attack rightside while moving. I can attack if i stay still. Heres my script.

 function Update() {
 
     if(Input.GetMouseButtonDown(0))
     animation.CrossFadeQueued("Sword_attack", 0.3, QueueMode.PlayNow);
           // play sword attack when left click is pressed
     
      if(Input.GetMouseButtonDown(1))
      animation.CrossFadeQueued("Sword_attack_rightside", 0.3, QueueMode.PlayNow);
           // play right side attack when right click is pressed
         
     if(Mathf.Abs(Input.GetAxis("Vertical")) > 0.1) 
 // if moving forward or backward, play the running animation
         animation.CrossFade("Sword_run", 0.2);
     else
         animation.PlayQueued("Sword_idle");
 // if you aren't running, switch back to the idle animation.
         if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.1)
         animation.CrossFade("Sword_run_side");
 // if moving right or left, play the side step animation.
 }


Can you guys help me at all?

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

1 Reply

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

Answer by Owen-Reynolds · Sep 08, 2012 at 03:21 PM

Look at the big animation page about layers, partial... and tricks to set up a system. Right now they are all on layer 0, so playing one will cancel anything else. Idle is working because PlayQueue specifically waits for Attack to finish.

Set the attack animation to layer 1+ and it will "win," covering up layer 0 animations while it plays.

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 oShadowkun · Sep 08, 2012 at 08:47 PM 0
Share

Thank you, I just put all my attack animations into layers inside the code, i thought you meant literally putting it into a layer in the Project.

animation["Sword_attack"].layer = 1;

animation["Sword_attack_rightside"].layer = 1;

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Animation Not Playing 1 Answer

1 FPS in Unity Timeline 0 Answers

How to change by-default fps in a 2D animation 3 Answers

Mecanim and double animations for a FPS 2 Answers

Animator doesnt work correctly after disabling then enabling a gameobject 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