Hello to the Unity community first time poster here! I have been going through the Walker Boys tutorials learning Unity development and I am kind of stumped as to why this is happening. I am on the tool development tutorial and during step 6 of the ani tool spreadsheet creating a 2d array offset and this is my code(C#) which works fine.; public class step62darrayoffset : MonoBehaviour { public int column; //u coordinate public int row; //v coordinate public float framesPerSecond = 8.0f; void Update() { int index = Mathf.RoundToInt(Time.time * framesPerSecond); //Time control FPS. index = index % (column * row); //End of the row(modulated). Vector2 size = new Vector2(1.0f / column, 1.0f / row); //scale. int u = index % column; int v = index / column; Vector2 offset = new Vector2(u * size.x, (1 - size.y) - (v * size.y)); //offset. print(index); renderer.material.mainTextureOffset = offset; //texture offset. renderer.material.mainTextureScale = size; //texture scale. } } But when i move the (u) and (v) variables to initialize them just after the index initialization when i run the animation it works for a few frames and then changes to a bunch of lines on the animation spreadsheet, like its changing the scale or something. Now i don't mind but i usually like to initialize variables at the top if i can and don't see why it would make a difference. Any explanation to this issue would be much appreciated!
first off, [code ] [/code ] tags make things much more readable (and gives line numbers ) Code (csharp): void Update() { int index = Mathf.RoundToInt(Time.time * framesPerSecond); //Time control FPS. index = index % (column * row); //End of the row(modulated). Vector2 size = new Vector2(1.0f / column, 1.0f / row); //scale. int u = index % column; int v = index / column; Vector2 offset = new Vector2(u * size.x, (1 - size.y) - (v * size.y)); //offset. print(index); renderer.material.mainTextureOffset = offset; //texture offset. renderer.material.mainTextureScale = size; //texture scale. } do you move lines 9 and 10 to just after line 3? (i.e. before line 5 where the index is updated...)