• 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 Frenzikk · Nov 26, 2014 at 10:09 PM · animationjavascriptspriteanimatoranimation controller

How do I animate a 2D sprite?

I imported a spritesheet, of a walk animation. I used the sprite editor to slice it. Then, I dragged the animation into the scene, and when I hit play, it animated it, perfectly fine. So, I looked at the properties of the thing I dragged into the scene. Under the Animator component, there was a property called Controller. In the scene, when I changed it to a different animation, and hit play, it switched the animation. The problem is, I can't seem to do that in script. How could I change the Controller in JavaScript?

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
0

Answer by g8minhquan · Nov 27, 2014 at 10:12 AM

For one character, you should create different Animation Clips (running / walking / idle / etc.) that are all controlled by 1 Animator Controller.

Then you change the Animation Clips by changing the conditions (Parameters) by using methods like

 Animator.SetBool();
 Animator.SetFloat();
 // etc.

A basic understanding of Mechanim (Unity's Animator Controller mechanism) is highly recommended.

http://docs.unity3d.com/Manual/Animator.html

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How can I reference an animator in another script so that it plays the desired animation when a button is clicked? 1 Answer

Animation state constantly being run, how to work around this? 1 Answer

Multiple Animation Controllers 0 Answers

animaton for a child of a gameobject 0 Answers

Is the new animation system leaking memory in iOS? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges