- Home /
find animation ?
Hi ...
How can I know if the player attached to him a specific animation ?
for example : ( just for explain my question )
if ( animation.find("Jump") ) **---> how can I do that ?**
animation.Play("Jump");
thanks...
Answer by whydoidoit · Apr 04, 2013 at 10:27 AM
You can just look through the list using Linq:
using System.Linq;
...
if(animation.Cast<AnimationState>().Any(c=>c.name == "Jump"))
{
animation.Play("Jump");
}
It's Javascript or UnityScript BTW (and you should really try to specify that in the question :) )
import System.Linq;
if(animation.Cast.<AnimationState>().Any(function(c) c.name=="Jump"))
{
animation.Play("Jump")
}
sorry
not working :( the same
Error $$anonymous$$essage : " There is no 'Animation' attached to the "$$anonymous$$nife" "
it's stopped on the if statement and give me the error message
Oh right - so you don't have an animation component on the $$anonymous$$nife then - in the inspector there needs to be the actual Animation component with the animations loaded.
You could change that code to read:
if(animation && animation["Jump"])
{
}
In that case, but it will never work without the Animation attached.
Answer by ricardo_arango · Apr 03, 2013 at 09:35 PM
You can use the brackets operator:
if(animation["Jump"])
animation.Play("Jump");
thank u for answering ... but the same problem
Error $$anonymous$$essage : " There is no 'Animation' attached to the "$$anonymous$$nife" "
I wanna if the animation not attached to the object , didn't try to play it
Ricardo's suggestion should work, you could however also try:
if (animation["Jump"] != null)
same problem ... it's stopped on the if statement and give me the error message .
Is the script attached to the same object as the Animation component?
yes ...
this is the point ...
some objects has the same animations names and the others not ... so I will send to all objects the animation I want if it has it will do it ,if not will not change his animation ...
Answer by Esterelle · Apr 04, 2013 at 09:43 AM
if (this.transform.Find("nameOfModel"))
{
this.transform.Find("nameOfModel").animation.Play("Jump");
}
Try and see if these few lines of codes can help you achieve what you want.
Answer by FLASHDENMARK · Apr 04, 2013 at 10:16 AM
Why do you not just create a variable for that animation, and then check if that variable != null:
var jumpAnim : AnimationClip;
if(jumpAnim){
animation.Play(jumpAnim.name);
}
Your answer
Follow this Question
Related Questions
my animation script does not work 0 Answers
Unity does not recognize reload animation for gun 1 Answer
Animation after 5 shots 1 Answer
Activating One Part of An Animation 2 Answers
Unity3D AI using animations 1 Answer