x


Making textures Scroll/ animate textures

how do i get a set texture to scroll from left to right, and or change a materials image over time?

more ▼

asked Jun 17, 2010 at 09:00 PM

Fishman92 gravatar image

Fishman92
2.8k 291 233 252

Look back at my question please Fishman92

Aug 04 at 09:04 PM DaPacoTaco
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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

That script will step through a texture sheet. The important bit is this particular line of code

renderer.material.SetTextureOffset ("_MainTex", offset);

With that you can also write a script that animates offset over time smoothly. In fact, here's an example of one:

using UnityEngine; using System.Collections;

public class AnimatedUVs : MonoBehaviour { public int materialIndex = 0; public Vector2 uvAnimationRate = new Vector2( 1.0f, 0.0f ); public string textureName = "_MainTex";

 Vector2 uvOffset = Vector2.zero;

 void LateUpdate() 
 {
     uvOffset += ( uvAnimationRate * Time.deltaTime );
     if( renderer.enabled )
     {
         renderer.materials[ materialIndex ].SetTextureOffset( textureName, uvOffset );
     }
 }

}

For changing the image, the most efficient way is to use a tiling texture, but if you must use different source images, you can use this:

http://unity3d.com/support/documentation/ScriptReference/Material-mainTexture.html

I.e.

renderer.material.mainTexture = myTexture;
more ▼

answered Jun 17, 2010 at 09:16 PM

Tetrad gravatar image

Tetrad
8.1k 62 65 131

awesome!!.......

Sep 02, 2010 at 01:15 PM Bentford

Thanks. This is a lot easier than having to set all the vertex UVs separately!

Jun 06, 2011 at 11:43 AM bernardfrancois

Great work....!! Worked for me too....

Jul 06, 2012 at 04:33 AM hirenkacha

superb man you are awesome thanks for this solution (y)

Jan 26, 2013 at 08:03 AM Sanky

Arent you worried about Vector2 overflow in uvOffset variable after time?

Dec 18, 2013 at 09:07 AM DuckOfDoom
(comments are locked)
10|3000 characters needed characters left

Hi, if you want animate multiple materials check this, hopes help you.

more ▼

answered Sep 01, 2011 at 10:46 PM

3D-Magic-VR gravatar image

3D-Magic-VR
56 39 31 31

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3603
x355
x111

asked: Jun 17, 2010 at 09:00 PM

Seen: 59925 times

Last Updated: Aug 04 at 09:04 PM