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
2
Question by bibleboy4u · May 27, 2015 at 11:22 AM · animation2dspritestop animations

How do I stop sprite animation on last frame?

Hi there, I have been using this script to animate a sprite sheet and I was wondering... How would I pause the animation on the last frame? I'm trying to do this for a falling animation. I've tried everything I can think of and spent hours trying to solve this myself. Can anyone out there help me out a bit? Thanks in advance for any answer provided!

Code:

 function aniSprite (columnSize, rowSize, colFrameStart, rowFrameStart, totalFrames, framesPerSecond){
 
     var index : int = Time.time * framesPerSecond;                                                    // time control fps
     index = index % totalFrames;                                                                    // modulate to total number of frames
     
     var size = Vector2 ( 1.0 / columnSize, 1.0 / rowSize);                                            // scale for column and row size
     
     var u = index % columnSize;                                                                        // u gets current x coordinate from column size
     var v = index / columnSize;                                                                        // v gets current y coordinate by dividing by column size
     
     var offset = Vector2 ((u + colFrameStart) * size.x,(1.0 - size.y) - (v + rowFrameStart) * size.y); // offset equals column and row
     
     GetComponent(Renderer).material.mainTextureOffset = offset;                                                    // texture offset for diffuse map
     GetComponent(Renderer).material.mainTextureScale  = size;                                                    // texture scale  for diffuse map    
     }











Comment
Add comment · Show 3
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 virgiliu · May 27, 2015 at 12:08 PM 1
Share

Why not use the built in sprite editor & animator ins$$anonymous$$d of offsetting the sprite manually? https://unity3d.com/learn/tutorials/projects/2d-roguelike/animations

This way you can trigger an animation by setting a boolean and when that boolean is no longer true you can go back to whatever state you want without having to write the business logic for animating the sprites and transitions from one state to the other

avatar image bibleboy4u · May 27, 2015 at 12:24 PM 1
Share

Thanks... I did not know about that animator. (It looks fantastic!) Is there a tutorial out there on how to crop the sprites into individual frames?

avatar image bibleboy4u · May 27, 2015 at 12:30 PM 1
Share

Thank you so much!

2 Replies

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

Answer by virgiliu · May 27, 2015 at 12:27 PM

Here you go https://unity3d.com/learn/tutorials/modules/beginner/2d/sprite-editor

http://docs.unity3d.com/460/Documentation/Manual/SpriteEditor.html

If you have the time watch this tutorial, it has basically everything you need to understand the sprite editor and animation and has some even more complex things like animation blend trees

https://unity3d.com/learn/tutorials/modules/beginner/2d/2d-controllers

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 bibleboy4u · May 28, 2015 at 11:48 AM 0
Share

Thanks again for all your help! The new animation tool is easy and fast!

avatar image
0

Answer by bibleboy4u · May 28, 2015 at 06:55 AM

The comment above solved my problem...

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 virgiliu · May 28, 2015 at 07:14 AM 0
Share

I converted it to an answer if you'd like to accept it :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Setting animator parameter on a single instance of a prefab sets the parameter for all instances 3 Answers

Sprites: Project Sprite to Mesh, allow for bending of sprites for 3d environments 0 Answers

Using same animation with different sprite sheets 0 Answers

Sprite Rect Moves Between Frames 0 Answers

Extra frame in simple animations? 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