- Home /
How to display gameobjects when i pause the game?
Ok, firstly i would like to tell you i'm struggling with this array command in javascript. I'm trying to create a script to pause the game, and once the game is paused, the script should display components in a few gameobjects which is held in an array. Look at my code, it says an error saying the variable 'i' already exists, but when i try to change it to something like 'j' nothing happens.
var obj : GameObject[]; var displayPauseObjects : boolean = false;
function Awake(){
obj = GameObject.FindGameObjectsWithTag("PauseObjects");
}
function Update(){
if(Input.GetButtonDown("Pause") && displayPauseObjects == false)
{
for(var i = 0; i < obj.length; i++){
obj[i].GetComponent(GUITexture).enabled = true;
}
displayPauseObjects = true;
}
//The First Part Works fine! When i press the pause key the game object's GUI Texture
//component gets displayed. But again to hide the components the code doesnt work.
if(Input.GetButtonDown("Pause") && displayPauseObjects == true)
{
for(i = 0; i < obj.length; i++){
obj[i].GetComponent(GUITexture).enabled = false;
}
displayPauseObjects = false;
}
}
Answer by MarkFinn · Dec 27, 2012 at 10:09 AM
Definitely change the second loop to
for(var j = 0; j < obj.length; j++){
obj[j].GetComponent(GUITexture).enabled = false;
}
(All changed to j).
If it is still not giving the result you expect then, there is a second problem, nothing to do with the choice of variable names.
Your answer
Follow this Question
Related Questions
What is wrong with my code? (Unity 2018, C#) 2 Answers
Camera displays view on object 1 Answer
Pause Menu Messes Up Game 1 Answer
How to Disable/Inactive NGUI Button on Game Pause? 0 Answers
Click on two buttons one at a time to get an image 0 Answers