- Home /
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
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);
}
}
}
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.
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.
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.
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.
That's genius. .. I'll definitely respond with my results. Thanks for the help.
Your answer
Follow this Question
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