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
0
Question by Vice_Versa · Jun 29, 2015 at 07:14 PM · animation2dunity5

how to make a basic 2d animation

so i have 33 different textures (of the same pciture, each one slightly different from the last). I want to animate them in a way that will replace the last picture with the new one, and i want it to go through all 33 of them in 2 seconds. the images im using are 2d, but they will be attached to a quad (this isnt a 2d game). How do i do this in unity? (ive never used the animation tools before). Do they need to be imported as sprites and used in the animator or could i just as easily do this through code?

Edit: i set all of the textures to materials and im having trouble actually cycling through them all for exactly two seconds. Every time i try to run unity now, the game freezes. heres my code

 using UnityEngine;
 using System.Collections;
 
 public class CursorAnimation : MonoBehaviour {
     float elapsedTime;
     public float timer;
      Material c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17,
     c18, c19, c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, c30, c31, c32;
     int spot;
     Material[] c_array;
     void Start()
     {
         c0 = Resources.Load ("mat_reticle", typeof(Material)) as Material;
         c1 = Resources.Load ("mat_c1", typeof(Material)) as Material;
         c2 = Resources.Load ("mat_c2", typeof(Material)) as Material;
         c3 = Resources.Load ("mat_c3", typeof(Material)) as Material;
         c4 = Resources.Load ("mat_c4", typeof(Material)) as Material;
         c5 = Resources.Load ("mat_c5", typeof(Material)) as Material;
         c6 = Resources.Load ("mat_c6", typeof(Material)) as Material;
         c7 = Resources.Load ("mat_c7", typeof(Material)) as Material;
         c8 = Resources.Load ("mat_c8", typeof(Material)) as Material;
         c9 = Resources.Load ("mat_9", typeof(Material)) as Material;
         c10 = Resources.Load ("mat_c10", typeof(Material)) as Material;
         c11 = Resources.Load ("mat_c11", typeof(Material)) as Material;
         c12 = Resources.Load ("mat_c12", typeof(Material)) as Material;
         c13 = Resources.Load ("mat_c13", typeof(Material)) as Material;
         c14 = Resources.Load ("mat_c14", typeof(Material)) as Material;
         c15 = Resources.Load ("mat_c15", typeof(Material)) as Material;
         c16 = Resources.Load ("mat_c16", typeof(Material)) as Material;
         c17 = Resources.Load ("mat_c17", typeof(Material)) as Material;
         c18 = Resources.Load ("mat_c18", typeof(Material)) as Material;
         c19 = Resources.Load ("mat_c19", typeof(Material)) as Material;
         c20 = Resources.Load ("mat_c20", typeof(Material)) as Material;
         c21 = Resources.Load ("mat_c21", typeof(Material)) as Material;
         c22 = Resources.Load ("mat_c22", typeof(Material)) as Material;
         c23 = Resources.Load ("mat_c23", typeof(Material)) as Material;
         c24 = Resources.Load ("mat_c24", typeof(Material)) as Material;
         c25 = Resources.Load ("mat_c25", typeof(Material)) as Material;
         c26 = Resources.Load ("mat_c26", typeof(Material)) as Material;
         c27 = Resources.Load ("mat_c27", typeof(Material)) as Material;
         c28 = Resources.Load ("mat_c28", typeof(Material)) as Material;
         c29 = Resources.Load ("mat_c29", typeof(Material)) as Material;
         c30 = Resources.Load ("mat_c30", typeof(Material)) as Material;
         c31 = Resources.Load ("mat_c31", typeof(Material)) as Material;
         c32 = Resources.Load ("mat_c32", typeof(Material)) as Material;
 
         c_array = new Material[]{c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, c30, c31, c32};
         timer = 2f;
         elapsedTime = 0;
         spot = 0;
     }
 
         public void animateCursor()
         {
         timer = 2.0f;
         elapsedTime = 0;
         while (timer > 0) {
             if (2.0 / 33 * (spot + 1) > elapsedTime)
                 spot++;
             if (spot > c_array.Length - 1) spot = 32;
             Debug.Log("SPOT: " + spot);
             Debug.Log("Timer: " + timer);
             GetComponent<Renderer> ().material = c_array [spot];
         }
         if (spot >= c_array.Length)
             spot = 0;
         timer = 2f;
         elapsedTime = 0;
         GetComponent<Renderer> ().material = Resources.Load ("mat_reticle", typeof(Material)) as Material;
     }
 
     void Update()
     {
         timer -= Time.deltaTime;
         elapsedTime += Time.deltaTime;
     }
 
 }
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
1
Best Answer

Answer by tyxman · Jun 29, 2015 at 09:15 PM

Why don't you create a animation using Sprites and attach that to the quad instead. When creating the animation add each new picture as a new frame.

Comment
Add comment · Show 8 · 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 Vice_Versa · Jun 30, 2015 at 02:40 AM 0
Share

i couldnt figure out how to do that before. I got it now though

avatar image tyxman · Jun 30, 2015 at 05:21 PM 0
Share

If you need help I've just done that exact thing the other day so feel free to ask.

avatar image Vice_Versa · Jul 05, 2015 at 06:00 AM 0
Share

actually i am having trouble with this. i changed all the textures for the material to sprites and im trying to add them to the animation, but i cant figure out how to actually do that. Pretty much everything in the animation window is greyed out and dragging them into the inspector for the animation doesnt seem to do anything either. So.. how do i actually add sprites to the animation?

avatar image tyxman · Jul 05, 2015 at 02:37 PM 0
Share

If it's grayed out that usually means you haven't created the .anim file so either in the top left of the animation window or the project window create a new animation file called whatever open that in the animation window. Then add the sprites. I got this idea from this tutorial https://unity3d.com/learn/tutorials/modules/beginner/2d/2d-controllers the animation instructions starts at around 20:00 $$anonymous$$ so try that

avatar image Vice_Versa · Jul 07, 2015 at 05:53 AM 0
Share

the link isnt working... Could the fact that Im making a 3d game be the reason it doesnt work?

Show more comments

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

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

Select Animations Freezing on First Frame 1 Answer

2D Animation does not start 1 Answer

Animation not playing Unity 5 (2D) 0 Answers

SpriteManager 2 1 Answer

Best way to do animate soldier? 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