x positions as array

Hi everyone … :slight_smile:
I found the next script in unity 3d manual:

// Change renderer's material each changeInterval
// seconds from the material array defined in the inspector.

var materials : Material[]; 
var changeInterval = 0.33; 

function Update () { 
    if (materials.Length == 0) // do nothing if no materials
        return; 

    // we want this material index now 
    var index : int = Time.time / changeInterval; 
    // take a modulo with materials count so that animation repeats 
    index = index % materials.Length; 
    // assign it to the renderer
    renderer.sharedMaterial = materials[index]; 
}

as you can see, this script can change materials array every 0.33 by the variable ‘changeInterval’ …
my request:
use the same script to change ’ X POSITION ’ instead of change ’ MATERIALS ’ every 0.33 … what i need to achieve that ?
regards

if you change the array of materials to an array of floats you’d get -

var xpositions: float[];
var changeInterval = 0.33; 

function Update () { 
    if (xpositions.Length == 0)
        return; 

    var index : int = Time.time / changeInterval; 

    index = index % xpositions.Length; 

    transform.localPosition.x = xpositions[index]
}

exact, this is what i want thanks callahan.44