I want to make the texture of a gameObject change after a random interval. The timer works in a test scene but doesn’t work in my game scene. I’ve tried a bunch of variations but haven’t been able to get it to work properly and am at a loss as to why not. I’d really appreciate some help understanding what’s going on and how to fix it.
Thanks,
Sue M.
#pragma strict
var welcomeTexture : Texture; // the welcome texture, when player first encounters game, before game play has started
var readyTexture : Texture; // the first texture after player has chosen to play
var goTexture : Texture; // the signal that the player can chose a game piece
var welcomeTex : boolean = false; // the welcome texture, when player first encounters game, before game play has started
var readyTex : boolean = false; // the first texture after player has chosen to play
var goTex : boolean = false; // the signal that the player can chose a game piece
var reset : GameObject; // the Reset button
internal var startTimer : float; // the moment the player clicks on the reset button, chooses to play
internal var randomStartTimeLimit : float; // the random length of time before texture change
internal var changeTexTimeLimit : float = 2.0; // the fixed length of time before texture change
internal var changeTex : boolean = false; // flag for texture change
function Awake ()
{
reset = GameObject.Find ("Reset"); // locate the Reset game object
}
function Start ()
{
renderer.material.mainTexture = welcomeTexture; // set this object's texture to Welcome Texture
}
function Update ()
{
if ( changeTex == true) // flag to change the texture
{
renderer.material.mainTexture = readyTexture; // set this object's texture to Ready Texture
randomStartTimeLimit = Random.Range(2.0, 4.0); // determine the random time length
startTimer = Time.time; // start the timer now
if (Time.time - startTimer > randomStartTimeLimit) // if the actual time minus the start time is more than the limit
{
renderer.material.mainTexture = goTexture; // set this object's texture to Go Texture
reset.GetComponent(ResetGame).goTex = true; // set goTex to true in the ResetGame script on reset GO
changeTex = false; // inactivate the flag to change the texture
}
}