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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by KG3 · Jul 13, 2013 at 03:09 PM · animationspritesspritemanager

Animataion of a Sprite

Hey Unity Community, I am trying to animate this sprite, in this scene.

alt text

I know Using sprite Manager is the way to go, although. When I did the code, I did not do it correctly, simply cause I could not figure out my Pixel Coordinates, Spacing, UV Spacing. Accurate enough. And when it animates, it was too large.

This is the newly created Sprite Sheet I made with Texture Packer I just gotten.

alt text

I have not tried it out with Sprite Manager. So I tried to create my own animation code.

which was this:

 using UnityEngine;
 using System.Collections;
 
 public class SpriteSheet : MonoBehaviour {
 
     public int numFrame = 6;
     public int currentFrame = 1;
 
 
     // Use this for initialization
     void Start () {
        
     
     }
     
     // Update is called once per frame
     void Update () 
     {
         transform.position = new Vector3(0f, 0f, 0.01f);
         
     }
 
     IEnumerable Wait()
     {
         yield return new WaitForSeconds(1);
         print("Wait" + Time.time);
     }
 
    
 
     public void animate()
     {
         float offset = 0;
         offset += 1.0f / numFrame;
         renderer.material.mainTextureOffset = new Vector2(offset,0);
         currentFrame += 1;
         while (currentFrame > numFrame)
         {
             offset = 0;
             renderer.material.mainTextureOffset = new Vector2(offset, 0);
             currentFrame = 1;
 
         }
     }
 
 
 
 
 
     
 }

This code makes the sprite goes to the origin, for some reason when it runs, instead of messing with the Material Offset, But actually I think I am messing with the particle offset.

I Have 2 questions:

  1. How can I easily find my Pixel Coordinates, UV corrdinates, and spacing for both using SpriteManagers. with PixelSpaceToUVSpace() and PixelCoordToUVCoord() in examples.

Else

  1. How can I get this Animation code do do what I want, or at least some tips?

capture.jpg (61.2 kB)
asuka.png (12.3 kB)
Comment
Add comment · Show 7
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 markedagain · Jul 13, 2013 at 04:16 PM 0
Share

im having a hard time understanding the question.

just looking at the code, im unsure how the logic goes. you have a yield function setup, but u never use it. and it the animate function, the while loop would run its whole iteration each frame, so you will always end up with only the last frame.

if you want to use the yield function, im guessing you would want to to put it into the while loop. so that each time the while loop iterates once it then waits, 1 second is proabaly to long. this is prob not exact as im not at home, but i think u want

 public IEnumerable  animate()
 {
     float offset = 0;
     offset += 1.0f / numFrame;
     renderer.material.mainTextureOffset = new Vector2(offset,0);
     currentFrame += 1;
     while (currentFrame > numFrame)
     {
         offset = 0;
         renderer.material.mainTextureOffset = new Vector2(offset, 0);
         currentFrame = 1;
         yield return new WaitForSeconds(1);
     }
 }

avatar image KG3 · Jul 13, 2013 at 04:21 PM 0
Share

I altered the code from this tutorial: http://www.youtube.com/watch?v=igxi8d2f5bc.

So I was kinda of confused on what he was doing.

If anything I wanna use Sprite$$anonymous$$anager. but I am just trying things out. I'll take your advice and keep hacking at it. I a just learning what the yield does as well

avatar image markedagain · Jul 13, 2013 at 04:23 PM 0
Share

ya , your use of yield is not correct , once u wrap your brain around it , it will be simple to see what to do.

looking at the function, it needs a bit more work , as u want to loop the current frame over the total numb of frames, then figure out your offset in the while loop

avatar image markedagain · Jul 13, 2013 at 04:26 PM 0
Share

mostly psudo code, but the idea should get you moving, i added a magic function that u need to figure out how to write

  public IEnumerable  animate()
 {
     int totalFrames = 8;
     int currentFrame = 0;
     
     while (currentFrame > numFrame)
     {
         offsetX = getOffset("x"); // this is tricky as u need to offset on the x and y. using mod for this is easy but hard to understand, let me know if u cant figure it out
         offsetY = getOffset("y");
         renderer.material.mainTextureOffset = new Vector2(offsetX, offsetY);
         currentFrame += 1;
         yield return new WaitForSeconds(1);
     }
 }
avatar image KG3 · Jul 14, 2013 at 02:21 AM 0
Share

Thanks, for that I 'll keep at it.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

17 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

Related Questions

Unity 2d Animation from spritesheet: How can I move the character according to the animation? 0 Answers

How do you make ripples for character in water? 0 Answers

Animation with Transparency Floats Above Ground 1 Answer

Unable to Buld & Run due to Unity Sprite Packer compiler error 2 Answers

Animating a Sprite Image in UI from 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