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 WesterlyCarrot9 · May 26, 2015 at 05:12 PM · c#animationplayframe

Attack Animation problem

Alright so i've written the code below and what i want is if the player skill is 1 then the enemy plays the attack animation. The problem is when he tries to play the attack animation it freezes at the first frame. Now i tried stopping the idle animation and then play the attack animation but nothing. I used a coroutine as well but still nothing. Any other suggestions? Notice that this is just the update function of my code :) Thanks!

 void Update () {
         if (Vector3.Distance (transform.position, player.transform.position) > 2) {
             chase ();
         } else {
             battle_mode_on = true;
             GetComponent<Animation>().Play (idle.name);
             player.GetComponent<Battle_Mode_Player> ().enemy_target = gameObject;
             healthbar = true;
         }
         if (health <= 0) {
             Destroy (gameObject);
             player.GetComponent<Battle_Mode_Player> ().enemy_target = null;
             player.GetComponent<PlayerStats> ().curxp += 30;
             healthbar = false;
         }
         if (battle_mode_on) {
             player_skill = player.GetComponent<Battle_Mode_Player>().skill_used;
             if(player_skill == 1){
                 GetComponent<Animation>().Play (attack.name);
             }
         }
     }
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 WesterlyCarrot9 · May 27, 2015 at 03:28 PM 0
Share

Anyone? :)

1 Reply

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

Answer by spiceboy9994 · May 27, 2015 at 05:56 PM

Just a suggestion, give a second review to your logic. At some point, 3 conditions may be met within the a single game cycle, causing switching animations from idle to attack over and over

Suppose that

 if (Vector3.Distance (transform.position, player.transform.position) > 2)

And

 if (battle_mode_on)

And

 if(player_skill == 1)

are all met. Then within the same game cycle your code will go from the "idle" animation to the "attack" animation within a single game cycle. Another thing to keep in mind is that you're running this on an update, so if the conditions are met on consecutive game cycles, the Animation.Play is fired on each cycle, causing it to play over and over from the beginning. If your game logic will never allow this, then you're good here.

Last logic point is to check if the requested animation is not playing before trying to start it back. If your animation is already a loop, that scenario will reset the animation to the initial frame over an over. If it's a loop and it's already playing, you don't need to invoke the play event anymore.

Here's a link that could help you with the last part:

http://answers.unity3d.com/questions/14599/check-if-a-spesific-animation-is-playing.html

Regards

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

20 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 avatar image avatar image

Related Questions

Animation keeps looping even on WrapMode.Once; 1 Answer

Multiple Cars not working 1 Answer

How to play one frame animation? 0 Answers

Animation Does Not Always Play Completely 3 Answers

Play a animation on an action? 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