# Lerp color of verts with position bigger than 1

Hi
On this page ([1]) there is a script to lerp color of verts in a object. How can i change the t value of lerp to be something other than a value between 0 and 1?

For example, if position.y of vert0 = 0.0 and vert3 = 1.0 than all verts between them are going to be changed gradient-like.
But if my verts are going to be between -30 and -126 than all of them will be lerped to the second color! How can i clamp all position.y of verts between those high points to be between 0 and 1 and still be accurately divided to preserve smooth gradient?

code:

``````function Start () {
objects = new GameObject.FindGameObjectsWithTag("gSides");
bottomColor.a = 0.0;
for (var x:int = 0 ; x<objects.Length ; x++) {
var mesh : Mesh = objects[x].GetComponent(MeshFilter).mesh;
var vertices : Vector3[] = mesh.vertices;
var colors : Color[] = new Color[vertices.Length];
var tChange : float;
for (var i = 0; i < vertices.Length;i++){

var worldPosition : Vector3 = objects[x].transform.TransformPoint( vertices*);*
``````
• ``````     if(worldPosition.y <startChange) {*
``````

colors = Color.Lerp(myColor, bottomColor, vertices*.y-2);*

* }*

* }*
* mesh.colors = colors;*
}
}
_*[1]: http://unity3d.com/support/documentation/ScriptReference/Mesh-colors.html*_

First you need to get the range - do this before your current for loop:

``````var minY=1000000.0;
var maxY=-10000000.0;
for (var i = 0; i < vertices.Length;i++) {
minY = Mathf.Min(vertices*.y, minY);*
``````

maxY = Mathf.Max(vertices*.y, maxY);*
}