Controlling the offset of a texture

Hey guys, i got this script from the manual:

function Update () {
    var offset : float = Time.time * scrollSpeed;
    renderer.material.SetTextureOffset ("_MainTex", Vector2(offset,0));
}

The way it is now the texture will keep offseting and needs 2 repeat(wrap mode), what i wanna do is to make the offset of the texture when reach say 1 returns to -3 and keep looping that way so i can clamp the texture. Any help will be appreciated since i’m new 2 programming

1 Answer

1
private var currentOffset : float = -3;
var resetTo : float = -3;
var maxOffset : float = 1;

function Update()
{
    currentOffset += Time.deltaTime * scrollSpeed;
    if(currentOffset > maxOffset)
    {
        currentOffset = resetTo;
    }
}

Sorry, I just succumbed to one of the greatest evils of the UnityScript language. The first three lines should be changed to private var currentOffset : float = -3; var resetTo : float = -3; var maxOffset : float = 1;