• 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 LijuDeveloper · Mar 19, 2014 at 12:09 PM · spritespritesruntimespritemanagersprite-animation

How to call sprite at run time

In my game i need to call sprite at run time . For example i have a sprite sheet of progress bar and progress bar sprite is sliced into 11 slice. How to call each slice at run time alt text

progressbarblue.png (18.2 kB)
Comment
Add comment · Show 1
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 Fattie · Mar 19, 2014 at 01:24 PM 0
Share

Just use 2DToolkit and save 3 months of work

3 Replies

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

Answer by wijesijp · Mar 20, 2014 at 07:06 AM

Create an anim tree with the sprites. Each animation is a level in the progress bar. You should have animations for each of the levels in the progress bar. To display any level in progress bar all you have to do is play the correct animation.

But why not put a w$$anonymous$$te sprite above t$$anonymous$$s blue progress bar and scale it? You will have very smooth control that way ...

Comment
Add comment · Show 1 · 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 LijuDeveloper · Mar 20, 2014 at 12:28 PM 0
Share

Thank you . Simple but it works

avatar image
2

Answer by wildex999 · Mar 19, 2014 at 12:40 PM

I would recommend you set it up as a spritesheet in Unity(Set sprite to multiple and slice it) and then use an animation where you manually progress it to the next frame when you need it to.

Check out: http://michaelcummings.net/mathoms/creating-2d-animated-sprites-using-unity-4.3

Comment
Add comment · Show 1 · 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 LijuDeveloper · Mar 20, 2014 at 11:40 AM 0
Share

Thank you for answer .Nice tutorial , that gives idea about how to make sprite ,and sprite animations.



Anyone looking for sprite animation , please refer above link



avatar image
0

Answer by trololo · Mar 19, 2014 at 03:25 PM

Hi, you can just display a certain bar depending of time:

   private IEnumerator ProgressBar(float time = 2f)
   {
       float startingTime = Time.time;
       float elapsedTime  = Time.time;
       float stopTime = 1f / time;
             
       int barID = 0;
             
       w$$anonymous$$le(barID < 10)
       {
           if((elapsedTime - startingTime) >= 1)
           {
               barID++;
               startingTime = elapsedTime;
           }
                 
           elapsedTime += Time.fixedDeltaTime * stopTime;
                 
           yield return null;
        }
    }

Where "barID" is the id in your array or in the spritesheet of the bar you want to display :)

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

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

23 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

Related Questions

How do I use the PlayAnim function in SpriteManager 2? 1 Answer

2D animation in 3D environment 0 Answers

Changing sprite properties at runtime 2 Answers

Change Sprite Pivot/Bounds from Script 2 Answers

Flipping Sprite on Client/Over Network 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