Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mimishak · Dec 27, 2012 at 09:00 AM · gamearraysgameobjectspausedisplay

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;
 }
 

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

getting udp package info inside unity (GlovePIE) 0 Answers

Passing through building 2 Answers

Why wont my character stop moving when it collides with the obstacles?,Why doesn't my movement script stop? 0 Answers

Moving Gameobject and Reseting Issues 3 Answers

Change the game window built 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges