- Home /
Switching Texture of menu Item locked/unlocked IOS
I have made a level select menu using an array of guiTextures. The code that controls the menu is here:-
var myTextures : GUITexture[] = new GUITexture[18];
function Update(){
for(var i=0;i<myTextures.length;i++)
{
if(myTextures[i].HitTest(Input.mousePosition))
{
for (var evt : Touch in Input.touches)
{
if (evt.phase == TouchPhase.Stationary)
Application.LoadLevel(i+1);
}
}
}
}
I was wondering how you would change the textures of the buttons according to whether they are locked and unlocked. Any help would be shweeeet. Thanks.
Comment
Best Answer
Answer by Seth-Bergman · Jul 27, 2012 at 02:31 PM
Here'a a simple (if somewhat inelegant) example:
var myTextures : GUITexture[] = new GUITexture[18];
var myLockedTextures : GUITexture[] = new GUITexture[18];
var myUnlockedTextures : GUITexture[] = new GUITexture[18];
static var currentLevelReached : int;
function Update(){
for(var i=0;i<myTextures.length;i++)
{
if(i+1 > currentLevelReached)
myTextures[i] = myLockedTextures[i];
else
myTextures[i] = myUnlockedTextures[i];
if(myTextures[i].HitTest(Input.mousePosition))
{
for (var evt : Touch in Input.touches)
{
if (evt.phase == TouchPhase.Stationary && currentLevelReached <= i+1)
Application.LoadLevel(i+1);
}
}
}
}
It would probably be better to move this out of the update though, and just update it when a new level gets unlocked..
Very cool Seth, yeah i'll trigger it when the level is completed. Your help is very much appreciated
Your answer
![](https://koobas.hobune.stream/wayback/20220613074803im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Easy way to center GUI Textures on a path? 1 Answer
Need help packing menu textures 1 Answer
"Foreach" in an Array? 1 Answer