• 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
Question by mahdi68 · Nov 21, 2011 at 06:11 PM · animationandroidspritespritesex2d

change sprite animation in ex2d ?

Hi , how can i change sprite animation in ex2d component ? i want to change animation from walk to jump when touching screen of android device can any one help me ? thanks

Comment

People who like this

0 Show 0
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

Answer by Anxo · Nov 21, 2011 at 06:59 PM

I dont know anything about ex2d but what you want to look for is what texture it is using and change that. Sprites are just sequences of images, change the sequence and you change the animation.

So if you are using sprite sheets and you have a sheet called "Characterwalk.jpg" and you have one called "CharacterJump.jpg" you would create var for each and then replace them at the appropriate time.

var characterWalk : Texture2D; var characterJump : Texture2;

then call them into your material when you need him to jump.

Comment
mahdi68

People who like this

1 Show 0 · 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

Answer by nantas · Nov 22, 2011 at 03:58 PM

First you add exSpriteAnimation Component to your gameObject with exSprite, and put your sprite animations into the list of the component.

Then whenever you want to change sprite animation, use this code in your script that has a reference to the sprite.

 var sprite: exSprite;
 
 sprite.spanim.Play ("hero_run_01");


The "spanim" is a property of exSprite class, you can always use it to get the sprite animation component. For more details, check out ex2D script reference:

exSprite

exSpriteAnimation

Comment
mahdi68

People who like this

1 Show 0 · 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

Answer by mahdi68 · Nov 23, 2011 at 11:17 AM

this is my code : var spAnim:exSpriteAnimation; function Start() { spAnim = GetComponent("exSpriteAnimation"); spAnim.Play("ninja_run"); }

Comment

People who like this

0 Show 0 · 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

Answer by neva · Feb 13, 2013 at 09:21 PM

Hello, I'm having trouble with exactly the same situation, but unfortunately the script above doesn't work for me.Fist of all, I'm using Unity 4.0.1f2. I added two animations to the Sprite Animation Object, but when I try to call the Start function again in order to play the second animation, the first animation (in the first if part) freezes and it stays like that forever. The code gets in the "else if" part but doesn't play the second animation. I'd appreciate it v much if you could help me. Thanks

 public var spAnim: exSpriteAnimation;
 
 function Start() { 
 if (something){
 
 spAnim.Play("name_of_the_1st_animation");
 }
 
 else if(somethingelse){
 
 spAnim.Play("name_of_the_2nd_animation");
 }
Comment

People who like this

0 Show 0 · 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

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Spritest look squashed and stretched in different screens. 1 Answer

Animation with Transparency Floats Above Ground 1 Answer

how should I make sprites 0 Answers

How do you integrate huge sprite sheets? 1 Answer

What is wrong with my EX2D code? 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