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 Guppie1337 · Apr 15, 2015 at 08:41 PM · c#animationbasic

Accept All int Values

I have a condition that checks the state of a sprite animation and destroys itself when it hits the desired state. I have done tons of searching to find any type of method that would work, but I have not succeeded. The following code works for 1 specific animation.

 if (animator.GetCurrentAnimatorStateInfo(0).IsName("FinishAnimation")
 {
     Destroy (this.gameObject);
 }

The difficulty I'm having is that each different object has the same type of animation (card flip), but use different sprite sheets. When saving the animation clips, I have added a number to the end as if to be an index of sorts. So the code I'm trying to get to is something like:

 if (animator.GetCurrentAnimatorStateInfo(0).IsName("FinishAnimation" + (any int value /*this is the "index"*/))
 {
     Destroy (this.gameObject);
 }

Is there an issue that the "index" I created in the file name is actually a string and not an int? For the same purposes, I'm also interested in accepting a specific range of values. I may be doing this very wonky, but I am new. Any advice is greatly appreciated. Thanks

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
1
Best Answer

Answer by hbalint1 · Apr 15, 2015 at 08:52 PM

I think your method could work. maybe you can add a .ToString() method to the end of "any int value". It will format as a string and concatenate the two spearate strings into one name like: FinishAnimation01. Put the whole thing into a for loop, so it can check all the animations at once. The other question could be just a simple if statement. So all in all:

  for(int i=0; i<animationsCount; i++)
  {
       if( i>= minValue && i<= maxValue){
   
           if (animator.GetCurrentAnimatorStateInfo(0).IsName("FinishAnimation" + i.ToString()))
           {
               Destroy (this.gameObject);
           }
   
       }
  }
Comment
Add comment · Show 7 · 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 Guppie1337 · Apr 17, 2015 at 06:53 PM 0
Share

I haven't had a chance to get around to it, but this seems pretty legit. I just don't understand how I would be able to deter$$anonymous$$e the int on the end of the animation file name. I'm sure that would be necessary in order to ever meet the condition of $$anonymous$$-max.

avatar image hbalint1 · Apr 17, 2015 at 08:01 PM 0
Share

so are you checking every animation frame-by-frame, that it has been finished? Then you can take the whole thing into a for loop, which goes from 0 to animationCounts, and use the local i variable ins$$anonymous$$d of someInt.

avatar image Guppie1337 · Apr 17, 2015 at 08:12 PM 0
Share

I'm actually just checking the last frame of every animation, which are named "FinishAnimation1", "FinishAnimation2" so on and so forth. The condition would be required to check for ALL the names by identifying the int I added to the file name. I have only managed to have it work with a single specified name.

avatar image hbalint1 · Apr 17, 2015 at 08:16 PM 2
Share

I meant this:

 for(int i=0; i<animationsCount; i++)
 {
      if( i>= $$anonymous$$Value && i<= maxValue){
  
          if (animator.GetCurrentAnimatorStateInfo(0).IsName("FinishAnimation" + i.ToString()))
          {
              Destroy (this.gameObject);
          }
  
      }
 }

So this will check every animation if it's done.

avatar image Guppie1337 · Apr 17, 2015 at 08:21 PM 0
Share

That's genius. .. I'll definitely respond with my results. Thanks for the help.

Show more comments

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

19 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

Related Questions

Change boolean after Animation is done 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

UNITY 2D: How to make a level Selection Menu Using DoTween? 1 Answer

Animation Event don't show C# methods 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