Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 bloodfall90 · Jul 21, 2015 at 08:06 AM · animatoranimator controllerattackmotion

How do I make it so my attack animation in my swords animation controller only play when I press the mouse button.

I've tried adding an attack Boolean and setting it up with a behavior script, I've tried using blend trees, I've tried using sub-state machines. This driving me crazy as I've been doing this for the past 6 hours trying to figure it out. HELP!

Comment
Add comment · Show 3
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 bloodfall90 · Jul 20, 2015 at 04:45 PM 0
Share

So far I have this as my behavior script for the the starting state that transitions to the attack state.

 using UnityEngine;
 using System.Collections;
 
 public class AttackAnimator : $$anonymous$$onoBehaviour {
     
     private Animator myAnimator;
     
     // Use this for initialization
     void Start () {
         
         myAnimator = GetComponent <Animator> ();
         
     }
     
     // Update is called once per frame
     void Update () {
         
         if (Input.Get$$anonymous$$ouseButtonDown (0)) 
             
             myAnimator.SetBool ("attack", true);
             //Invoke ("StopAttack", 0.1f);
             
             
         }
 
     
     //void StopAttack () {
     
     //animator.SetBool ("attack", false);
     
     //}
 }
avatar image notoriousnary · Jul 21, 2015 at 08:27 AM 0
Share

Can you add a screenshot of how your animator controller is set up ?

avatar image bloodfall90 · Jul 21, 2015 at 06:01 PM 0
Share

http://imgur.com/CmafYB7

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Requiem36 · Jul 21, 2015 at 09:08 AM

From the code you've posted, you're only setting the bool to true once and never setting it to false. This will trigger the "attack" state indefinitely, so you have to set it back to false eventually. From what you have commented in your code, you were on the right track, thought I would advise using the actual animation time for the invoke delay.

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 bloodfall90 · Jul 21, 2015 at 05:57 PM 0
Share

I realize it will need to be set back. But for now I just wanted it to get working.

avatar image
0

Answer by notoriousnary · Jul 21, 2015 at 07:22 PM

According to your code

  if (Input.GetMouseButtonDown (0)) 
              
              myAnimator.SetBool ("attack", true);

but your animator setup http://imgur.com/CmafYB7 is expecting a bool called fire which explains why the its not working. (based on the code you posted) set it to myAnimator.SetBool("Fire", true); and it should work.

Comment
Add comment · Show 2 · 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 bloodfall90 · Jul 21, 2015 at 07:52 PM 0
Share

That was actually previous code and my new stuff looks the exact same but with the right names. Still doesn't work.

avatar image notoriousnary · Jul 21, 2015 at 08:04 PM 0
Share

Without loading your project up in unity, I don't think i can help much further. as long as the script is attached to the correct GameObject in the editor.

for reference, i'm using the same system in my project

Animator setup : http://imgur.com/Aztsgqn Script setting the flag: http://imgur.com/bI6eey2 Animator at runtime: http://imgur.com/DxftWVj

If you want to share your project in some way you feel comfortable I might be able to help work it out.

avatar image
0

Answer by Ness · Jul 21, 2015 at 08:52 PM

There is some transition error displayed on the screenshot of you animator window, never came across it, fixing it would be my first step to debug this problem.

Furtheremore to debug this, I would setup game scene window next to animator window and observe behaviore of animator while clicking. Maybe your exit trigger is setup in a way that it exits to the previous animations just after entering it. Make a gif of animator window and post it, maybe this will tell more.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I access the States of an AnimationController with c#? 1 Answer

Why do my animations only play once? 1 Answer

Animator - Do After Playing Animation 1 Answer

Animation Impulse System? 1 Answer

Quaternion to Matrix conversion failed (5.3.4p5) 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