• 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
4
Question by kadamati · Mar 16, 2014 at 10:08 AM · animation controller

How to enable/disable animator by script?

Hi, I have an Animator attached with a gameobject. It has a controller and avatar. I removed the tick beside the animator before pressing the play button, so, it does not automatically plays. Now, while playing the game, if I check on the tick, it plays the desired animation. I want to write a script which receives a keycode (say space bar) and then enables the animator during play time.

How?

Please help.

Comment
Add comment · Show 2
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 kadamati · Mar 16, 2014 at 09:04 AM 0
Share

By the way, I am not sure whether the tag is appropriate here. But this is my very first question. So unity did not allow me to choose my own tag.

avatar image kadamati · Mar 16, 2014 at 08:00 PM 0
Share

I better explain a little more. I have animated a cube explosion in blender and imported it into unity. Now, the imported prefab has thirty-four chunks. Each of the chunks has its own animation inherited from blender. When I add the prefab in my scene, it doesn't automatically starts playing, but when I drag and drop the Default Take clip on the prefab in hierarchy window, and hit play, it plays once. Please note that, no any Animation component has been attached so far. But there is an Animator attached.

The problem is, I cannot control this animation. I attached an Animation (not Animator) component to the prefab (i.e. Component > $$anonymous$$iscellaneous > Animation ), and set the "Default Take" at its "Animation" field, so that i can control it with gameObject.Animation.Play(). But now, unity says,

The AnimationClip 'Default Take' used by the Animation component 'fractureTest' must be marked as Legacy.

alt text

(fractureTest is the name of my prefab) <\br> <\br> Now, I am not going to attach thirty-four animation component separately with all the chunks. It would be extremely ridiculous and time consu$$anonymous$$g. :-(

I am in a fix.

animatorproblem.png (69.4 kB)

6 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by mbhagat · Dec 26, 2018 at 12:27 PM

Animator anim; void Start() { anim = GetComponent(); } void OnTriggerEnter(Collider col) { anim.enabled = true; anim.Play("Death"); }

Here I have enabled animator run time as well play required animation. Hope it helps !

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
  • ‹
  • 1
  • 2

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Related Questions

How to control speed of animation on Unity by a .txt file? 1 Answer

Animation state not transitioning at 100% 1 Answer

How can I reset my idle animation? 1 Answer

Animation begins at start of Gameplay before colliding with trigger 2 Answers

Animations don't work with humanoid avatars 0 Answers


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