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 billyda59 · Jun 30, 2013 at 05:58 AM · weaponanimation script

How do I get my melee animations to play?

I have a first person controller with a weapon attached to it. The weapon has 2 animations, an idle and an attack. How do I get the attack animation to play upon clicking the mouse? I tried attaching this script to the weapon:

 function Update () 
 {
 if(Input.GetButtonUp("Fire1"))
 {            animation.Play("tools_stone_axe_attack01.anim", PlayMode.StopAll); }}



I have this java script attached to the game object that has the animations. I can't really code whatsoever, but I try to patch together code from different answers and tutorials I find. Apparently this code doesn't work. The Unity console says "The animation state tools_stone_axe_attack01.anim could not be played because it couldn't be found!" This confuses me. I know the animation is there. Did I format the name incorrectly?

I just want my attack animation to play on primary mouse button clicking and I want the animation to switch the the idle animation when it's done.

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 bodec · Jun 30, 2013 at 06:18 AM 0
Share

remove the playmode.stopall and see if that doesn't get you swinging

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by billyda59 · Jun 30, 2013 at 04:06 PM

I understand that Unity isn't finding the animation.alt text

1 - The scripted game object DOES have the animations attached. The game object is selected in the screenshot and you can see the inspector on the right of the screen. The animation element shows 2 animations.

2 - I think the code doesn't like all the underscores I used in the animation name. I've tried removing the animation file extension in the code, but that didn't help. This is the only thing that I'm not sure about.

3 - You can see in the screenshot that the script IS attached to the game object.

Something maybe worth noting is that I've made these animations using unity, not blender.


screen1.jpg (279.7 kB)
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 ownerfate · Feb 12, 2014 at 11:01 PM 0
Share

or another option is using an Animation State $$anonymous$$achine.

it's a good way of blending two or more animations together.

avatar image
0

Answer by ownerfate · Aug 31, 2013 at 11:19 AM

i have only got as far as playing the animation on Mouse click.

i can't figure out how to force it back to an Idle state.

but this is how i animated stuff for me.

SCRIPT:

   function Update(){
     
     if(Input.GetMouseButtonDown (0)){
     
         GameObject.Find("GavinBlade").animation.Play("ghostBladeAttack");
     }
 

GameObject.Find(" name of the object that holds the animation clips ").animation.Play(" Name of the Animation itself ");

i hope this is somewhat helpful.

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

18 People are following this question.

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

Related Questions

how can you mount weapons when they do not appear until runtime? 1 Answer

I cant add scripts to my weapons,i can't add Scripts to my weapon 1 Answer

How to make shotgun unity 3d 0 Answers

Can I use Mecanim animation clips in Legacy? 1 Answer

How to play the animation completely on mouse click 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