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 CMNaticGames · Jan 22, 2014 at 02:22 PM · textureprogramminganimating

How to animate a texture

Hey, I'm pretty much new to Unity and I'm using the free version.

I have made a series of about 40 pictures of water moving. For example:

alt text alt text

(Not sure if they're the best examples out of the lot)

Now, I've got my plane and I've found a script online (unity community)

 #pragma strict
 
 var uvAnimationTileX = 24; //Here you can place the number of columns of your sheet. 
                            //The above sheet has 24
  
 var uvAnimationTileY = 1; //Here you can place the number of rows of your sheet. 
                           //The above sheet has 1
 var framesPerSecond = 10.0;
  
 function Update () {
  
     // Calculate index
     var index : int = Time.time * framesPerSecond;
     // repeat when exhausting all frames
     index = index % (uvAnimationTileX * uvAnimationTileY);
  
     // Size of every tile
     var size = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY);
  
     // split into horizontal and vertical index
     var uIndex = index % uvAnimationTileX;
     var vIndex = index / uvAnimationTileX;
  
     // build offset
     // v coordinate is the bottom of the image in opengl so we need to invert.
     var offset = Vector2 (uIndex * size.x, 1.0 - size.y - vIndex * size.y);
  
     renderer.material.SetTextureOffset ("_MainTex", offset);
     renderer.material.SetTextureScale ("_MainTex", size);
 }

  

Now to my question, how can I turn these PNG's into one animation and put it onto my water plane so I can get realistic looking water without using the pro feature.

Sorry for the length question,

Thanks in advance, CMNatic

frame_0001.png (103.3 kB)
frame_0002.png (103.6 kB)
Comment
Add comment · Show 2
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 robertbu · Jan 22, 2014 at 03:04 PM 0
Share

Not sure where you are having a problem. Note if you don't want to put all of these textures into a single texture, you can animate the individual images using this script:

http://wiki.unity3d.com/index.php/Texture_swap_animator

You will drag and drop the textures (in order) into the 'frames' array in the Inspector.

avatar image CMNaticGames · Jan 22, 2014 at 06:00 PM 0
Share

It worked like a charm! Thanks so much for your answers. Can I be cheeky? :D

I've got it working but it's understandably all dis-configured, is there anyway that I can scale all the frames so that they look nice and proper on any size plane?

Thanks in advanced, C$$anonymous$$Natic

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · Jan 22, 2014 at 04:15 PM

That code is (I think) for animating a spritesheet. That's a standard trick, invented long before Unity. You can look up examples and how to make and use them anywhere. Then, those top two lines about TileX and TileY should make complete sense, including what you need to change them to.

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 robertbu · Jan 22, 2014 at 04:54 PM 0
Share

@Owen Reynolds - The source is from the wiki, and you are right it is animating a spritesheet:

http://wiki.unity3d.com/index.php?title=Animating_Tiled_texture

avatar image
0

Answer by listener · Jan 22, 2014 at 04:52 PM

Like Owen said, it's spritesheet animation. Basically rough steps would be:

  • Combine all images and make spritesheet x by y

  • Assign spritesheet texture to object you want to use

  • Offset texture by x amount and by y amount

For example you have 40 images you can make spritesheet 6x7 last row will have only 4 images. Since Unity UV goes from 0 to 1 your X offset will be 1/6=0.166 and Y offset 1/7= 0.142 So now you just offset by .166 till the last image then increment Y offset by .142 and call this routine X times per second.

Here is simple example in Documentation

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.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Multiple Cars not working 1 Answer

Trying to achieve this color effect 0 Answers

How can i make my ragdoll splat blood on collision? 1 Answer

texture is the background colors but negative. How to do that? 1 Answer

Primitive block texturing (In code) HELP 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