change mesh UV coordinates within texture atlas

I have one mesh whose UV are at the left side of 0 to 1 space, and one 512x512 texture atlas which contains left and right different state of object, left normal and right aged.
when I call a function, I’d like to make the mesh UVs all shift from its left position to right changing its appearance from normal to aged.
here is sample code and I am not sure how to do the shifting.

``````public void ChangeState()
{
Mesh mesh = GetComponent<MeshFilter>().mesh;

Vector3[] vertices = mesh.vertices;

Vector2[] uvs = new Vector2[vertices.Length];

for(int i= 0; i < uvs.Length; i++)
{
uvs *= new Vector2(what do I do here?);*
``````

// it is not new Vector2(vertices_.u + 256, vertices*.v);
// nor new Vector2(vertices.u + 0.5, vertices.v);
// what is the correct way?>
}
mesh.uv = uvs;
}*_

Assuming things are setup as you describe, you can do something like this:

``````public void ChangeState() {

Mesh mesh = GetComponent<MeshFilter>().mesh;
Vector2[] uvs = mesh.uv;

for (int i = 0; i < uvs.Length; i++) {
if (uvs*.x >= 0.49f) {*
``````

_ uvs*.x = 0.99f;_
_
}_
_
else {_
_ uvs.x = 0.501f;
}
}
mesh.uv = uvs;
}*
There are a couple of things to note here. First this code expects the texture to be reflected across the vertical axis and the two sides take up the whole atlas. Second, I only flop it one way. You could easily write code that flops based both ways. Third, I’ve pulled the uvs values in slightly, which may or may not be needed._

Found alternative solution [here][1].

For your case it would be (untested):

``````bool oldSide;

renderer.material.SetTextureScale("_MainTex", new Vector2(0.5f, 1));
renderer.material.SetTextureOffset("_MainTex", new Vector2(oldSide ? 0.5f : 0, 0));
``````

And as for your code (also untested):

``````         Mesh mesh = GetComponent<MeshFilter>().mesh;
Vector3[] vertices = mesh.vertices;
Vector2[] uvs = new Vector2[vertices.Length];

for(int i= 0; i < uvs.Length; i++)
uvs*.x += 0.5f;*
``````

mesh.uv = uvs;
And minus 0.5f to shift it back. Should work.
[1]: Shifting the UV's of a plane - Unity Answers