Shifting UV of a Plane for Sprite Animation

How would you shift the UV of a plane for sprite animation using the offset prescribed by the code here. More Specifically, this code

using UnityEngine;
using System.Collections;
 
class AnimateTiledTexture : MonoBehaviour
{

public int columns = 2;
    public int rows = 2;
    public float framesPerSecond = 10f;
 
    //the current frame to display
    private int index = 0;
 
    void Start()
    {
        StartCoroutine(updateTiling());
 
        //set the tile size of the texture (in UV units), based on the rows and columns
        Vector2 size = new Vector2(1f / columns, 1f / rows);
        renderer.sharedMaterial.SetTextureScale("_MainTex", size);
    }
 
    private IEnumerator updateTiling()
    {
        while (true)
        {
            //move to the next index
            index++;
            if (index >= rows * columns)
                index = 0;
 
            //split into x and y indexes
            Vector2 offset = new Vector2((float)index / columns - (index / columns), //x index
                                          (index / columns) / (float)rows);          //y index
 
            renderer.sharedMaterial.SetTextureOffset("_MainTex", offset);
 
            yield return new WaitForSeconds(1f / framesPerSecond);
        }
 
    }
}

I understand that I use Mesh.uv to manipulate the co - ordinates. I did so with a pre determined offset for a static sprite, but am having problems with animated sprites.

Any ideas??

Thanks for the help in adbvance.

Cheers!!

There is an error in calculating offset. To get right column you need a remainder. And another thing for row.

offset.x = ((float)(index % columns)) / (float)columns;
offset.y = ((float)(index / columns)) / (float)rows;

And by the way if you do renderer.sharedMaterial.SetTextureOffset() you will change all the GameObjects with this sprite. Do renderer.material.SetTextureOffset() instead.