Change Texture Script

Hi guys, I made a short script to change the texture on the scene, but would like the others to take a look on it to improve it, any hint is welcome.

Script:

#pragma strict

var texture : Texture2D[];

var minWait : int;
var maxWait : int;

private var time : int;
private var nextTime : int;

function Start () {
	newNextTime();
	if (minWait <= 0) minWait = 2;
	if (maxWait <= 1) maxWait = 10;
}

function Update () {
    if (time >= nextTime) {
        if (texture.Length != 0) {
            renderer.material.mainTexture = texture[Random.Range( 0, texture.Length)];
            newNextTime();
        }
    } 
    time = Time.time;
}

function newNextTime () {
	nextTime = time + Random.Range(minWait, maxWait);
}

Thanks in advance. :wink:

Below is a recording of the current result reached by this script.

Thanks in advance. ;D

Love to see the Skyrim screens come alive in this video! :slight_smile:

In the video I’m using the free version of Unity3D. :frowning:

Instead of testing for a random value every frame, i would generate a random length of time until the next change.

if time > nextTime
nextTime = time + randomLengthOfTime
changeImage()

updated script, thanks for the tips! :hushed:

Comments: in my project, I use the name of variables in Portuguese, however translate to the better understanding of all. I’m also using integer type because I have no interest in the accuracy of the exchange.