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
1
Question by Fadi · Apr 03, 2013 at 09:28 PM · animation

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...

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

4 Replies

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

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");
    }
Comment
Add comment · Show 5 · 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 Fadi · Apr 04, 2013 at 10:48 AM 0
Share

c=>c ?? please could convert it to java ...

avatar image whydoidoit · Apr 04, 2013 at 10:51 AM 0
Share

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")
   }
avatar image Fadi · Apr 04, 2013 at 11:02 AM 0
Share

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

avatar image whydoidoit · Apr 04, 2013 at 11:06 AM 0
Share

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.

avatar image Fadi · Apr 04, 2013 at 11:34 AM 0
Share

Thank u ^_^

avatar image
1

Answer by ricardo_arango · Apr 03, 2013 at 09:35 PM

You can use the brackets operator:

 if(animation["Jump"])
     animation.Play("Jump");
Comment
Add comment · Show 5 · 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 Fadi · Apr 04, 2013 at 09:24 AM 0
Share

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

avatar image save · Apr 04, 2013 at 09:39 AM 0
Share

Ricardo's suggestion should work, you could however also try:

 if (animation["Jump"] != null)
avatar image Fadi · Apr 04, 2013 at 09:43 AM 0
Share

same problem ... it's stopped on the if statement and give me the error message .

avatar image save · Apr 04, 2013 at 10:07 AM 0
Share

Is the script attached to the same object as the Animation component?

avatar image Fadi · Apr 04, 2013 at 10:16 AM 0
Share

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 ...

avatar image
0

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.

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

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);
 }
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

15 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

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


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