x


Explain this script :) plz

 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, 2.0 - size.y - vIndex * size.y);



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

        renderer.material.SetTextureScale ("_MainTex", size);



    }

Right can someone explain what few lines in this code mean? what does   

renderer.material.SetTextureOffset ("_MainTex", offset);
do ? I am new to unity when it comes to programming 2d sprites i found this on Unity Wiki by the way :) 

the second is:

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

and also what does "_MainTex" do in this code?

and last:

What is this line of code doing ?????7

var offset = Vector2 (uIndex * size.x, 2.0 - size.y - vIndex * size.y);

so if someone can explain that to me i would be very great full thanks :)

more ▼

asked Feb 28 '11 at 06:50 AM

MC HALO gravatar image

MC HALO
878 74 94 111

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

This script cycles through the lines and columns of a sprite texture to get a flipbook animation effect. It then supplies the new u and v texture coordinates to the renderer.

_MainTex is the name of a texture in a shader, usually the main texture of the material.

Take a look at he reference:
Material.mainTexture
Material.SetTexture

more ▼

answered Feb 28 '11 at 08:12 AM

efge gravatar image

efge
5.1k 5 14 38

Thank you very very much :)

Feb 28 '11 at 12:22 PM MC HALO
(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:

x5098
x3749
x215
x59

asked: Feb 28 '11 at 06:50 AM

Seen: 1110 times

Last Updated: Feb 28 '11 at 06:50 AM