- Home /
Change Gui Textre to another overtime? and reset script when player passes through trigger
Well Basically i want a Gui Texture to change to another gui texture 1 min later, and then to another Gui Texture another 1 min later, (max 2 times) and when u walk through a trigger the script resets happening all over again.
SO e.g. green icon goes to yellow, yellow icon goes to red (1 min intervals) player walks through a Trigger, it all resets going back to the first Gui texture happening all over again.
hope i worded this correctly. any ideas? i wouldnt know how to start a script like this.
Answer by aldonaletto · Apr 10, 2012 at 01:27 PM
You can set a timer to loop through the textures in Update, and reset this loop in OnTriggerEnter - like this (trigger script):
var gTexture: GUITexture; // drag the GUITexture here var textures: Texture2D[]; // define the textures here var interval: float = 60.0; // interval in seconds
private var timer: float = 0.0; private var curTex: int = 0;
function Update(){ timer -= Time.deltaTime; // decrement timer if (timer < 0.0) SetTexture(); // set the texture }
function SetTexture(){ gTexture.texture = textures[curTex++]; // assign current texture and advance pointer curTex = curTex % textures.length; // return to first one if passed the last timer = interval; // reset timer }
function OnTriggerEnter(){ curTex = 0; // reset texture pointer... SetTexture(); // assign current texture and reset timer }
Your answer
![](https://koobas.hobune.stream/wayback/20220613070131im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Best way to handle clicking on a GUI.DrawTexture? 1 Answer
Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer
Write a Shader for GUI (GUITexture or scripted GUI) 0 Answers
Help! Hiding/showing GUITextures! 1 Answer
I am trying to send a 2D texture to my first person controller to display on the GUI 1 Answer