Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 nwitkoski · Apr 14, 2011 at 02:18 AM · guivariablebooleancheck

Pass bool value from multiple objects to one file to check their values?

I have 4 cubes, when I click on a cube its position goes up and a boolean isRaised changes to true. When I click it again the cube goes back to its original spot and the boolean goes back to false. Is there a way I can click a gui button to see if all the cubes are up at one time?

I have created the cubes. I have created individual scripts for each cube and attached it to the cube so they all have unique booleans. So each cube has its own name and its own script attached to it and nothing else. What additional steps do I need to take to get this to work? Or, are there any other ways to solve this problem?

Thanks.

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
Best Answer

Answer by Justin Warner · Apr 14, 2011 at 02:21 AM

Give the cubes their own tag, and loop through them, check the countTotal to countUp.

var boxes : GameObject[]; var nextLevelCount = 0; var boxUpCount = 0; var boxTotalCount = 0; boxes = GameObject.FindGameObjectsWithTag("Box");

//.boxUp is the boolean in the script with the boolean of whether it's up or not.

for (var box : GameObject in boxes) { if(box.GetComponenet(SCRIPTNAMEHERE).boxUp == true) { boxUpCount++; } boxTotalCount++;

 if(box.ToString == "Box1")
 {
   nextLevelCount++;
 }
 if(box.ToString == "Box5")
 {
   nextLevelCount++;
 }

}

if(boxUpCount == boxTotalCount) { //Do whatever when all up. }

if(nextLevelCount == 2) { //Load scene. }

Not tested, but should work/get the point across =) Good luck!

Comment
Add comment · Show 5 · 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
avatar image nwitkoski · Apr 14, 2011 at 02:36 AM 0
Share

Thank you very much for your quick reply. Is there a way I can check to see which specific boxes are up though? It is going to be part of a $$anonymous$$i game and I actually want to be able to set a certain combination. Like the first and the third box up and the second and fourth down would allow the user to go to a new scene. Does that make sense?

avatar image nwitkoski · Apr 14, 2011 at 02:44 AM 0
Share

What if, I just change the boolean to a global var, can I then, access each individual script to see if it is true or not? would that work?

avatar image Justin Warner · Apr 14, 2011 at 02:55 AM 0
Share

You can get the actual name of the game object with: http://unity3d.com/support/documentation/ScriptReference/Object.ToString.html?from=GameObject And with that, compare the name with one of the things in the for:each loop, and have a counter that counts when it's good, and then do a compare at the bottom... I'll edit, 1 sec.

avatar image Justin Warner · Apr 14, 2011 at 02:57 AM 0
Share

If that makes sense... And you can just compare the names =).

avatar image nwitkoski · Apr 14, 2011 at 03:02 AM 0
Share

excellent. Thank you very much.

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

No one has followed this question yet.

Related Questions

Does anyone know about BeingChangeCheck function? 0 Answers

How to stop a boolean from going back to false 1 Answer

Input player name to a variable 2 Answers

How can I Include string variables in Rich Text? 1 Answer

How do I check teh value of a variable in another script. 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