Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by anarchyABC · May 31, 2011 at 08:21 PM · togglevisibilityvisibleon and off

How do I Toggle between alternatives?

I am trying to figure out how to use Unity for Planning and Architectural purposes, specifically to toggle between Existing Conditions and Proposed Conditions. I've previously used Blitz3D for creating these simulations but am now thinking about using Unity, which in some ways seems much easier, and in other ways, seems much more difficult.

So, I've gone through a few attempts, and this is the closest I am coming:

code:

function Update () {

 if (Input.GetButton("Alternative1")){
         exists = GameObject.FindGameObjectsWithTag("Exist"); //returns all of the objects that are "tagged" with the attribute "Exist"
         for (var exist: GameObject in exists) {
             exist.renderer.enabled = false;
         }
         Alt1s = GameObject.FindGameObjectsWithTag("Alt1");//returns all of the objects that are "tagged" with the attribute "Alt1
         for (var alt1 : GameObject in Alt1s) {
             alt1.renderer.enabled = true;
         }
 }

 if (Input.GetButton("Existing")){
         exists = GameObject.FindGameObjectsWithTag("Exist"); //returns all of the objects that are "tagged" with the attribute "Exist"
         for (var exist: GameObject in exists) {
             exist.renderer.enabled = true;
         }
         Alt1s = GameObject.FindGameObjectsWithTag("Alt1");//returns all of the objects that are "tagged" with the attribute "Alt1
         for (var alt1 : GameObject in Alt1s) {
             alt1.renderer.enabled = false;
         }
 }

}

(this is my first post...not sure how to get the code into that neat little code box...I would think it would be part of the Markdown Basics, but I guess it's not.)

Here's what happens: The simulation starts with Existing showing (that's good). When I press "1" (which is the "Alternative 1" button) then the meshes tagged with "existing" are toggled off (or rather, their rendering is disabled), and the meshes tagged with "alt1" are turned on (rendering enabled). (this is all good too!)

When I press "e" (which is the "Existing" button) then the meshes tagged with "alt1" turn off (which is good). Unfortunately, the "existing" meshes don't come back.

However, if I press "1" again, the alternative 1 meshes come back, and when I press "e" for the second time, the alternative 1 meshes disappear and oddly the existing meshes come back!

Additionally, when I create a webplayer, it acts in a different way. You can see it here: my example

What happens in the webplayer is that when I hit the "1" key, the alternative 1 meshes toggle on and off, which is exactly what i want. When I eventually get to the Existing meshes, and I hit the "e" key, then I can toggle the Existing on and off...But, if the existing meshes are toggled on, I want to be able to hit the "1" key and turn off the existing and turn on alternative 1 meshes at the same time. I can't seem to figure out how to do this.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Meltdown · May 31, 2011 at 08:37 PM

You might also want to try setting your GameObjects to active or not using the active property instead of toggling the renderer status.

Give that a try.

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
avatar image
0

Answer by anarchyABC · Jun 01, 2011 at 12:53 AM

Thanks for the hint Meltdown, however I did try it, and it's really still the same. Here is the code I'm using:

 var alt1s : Array;
 var exists : Array;
 var alt1 : GameObject;
 var exist : GameObject;
 function Start ()
 {    
 
     alt1s = GameObject.FindGameObjectsWithTag("Alt1");//returns all of the objects that are "tagged" with the attribute "Alt1
     for (var alt1 in alt1s) {
         alt1.active = false;
     }
     exists = GameObject.FindGameObjectsWithTag("Exist"); //returns all of the objects that are "tagged" with the attribute "Exist"
     for (var exist in exists) {
         exist.active = true;
 
     }
 }
 
 function Update () {
     if (Input.GetButton("Alternative1")){
             for (var exist in exists) {
                 exist.active = false;
             }
             for (var alt1 in alt1s) {
                 alt1.active = true;
             }
     }
     if (Input.GetButton("Existing")){
             for (var exist in exists) {
                 exist.active = true;
             }
             for (var alt1 in alt1s) {
                 alt1.active = false;
             }
     }
 }

And here's a link to how it looks as a webplayer in Unity: Unity Example

Unfortunately this time, it doesn't even begin with existing conditions (the three barns), and it is still very reluctant to show the existing conditions when I type "e". If the player is showing the existing conditions, and I press "1", then it will turn off existing conditions, and turn on alternative 1. However, when it is showing alternative 1 and I type "e", it will NOT turn off alternative 1, and it will NOT show existing conditions. It will show existing conditions when I hit "1" however. So it seems that everything relies on "1" being hit, "e" is subordinate to the "1"...however, from what I can tell, I've written it so that they should both be behaving exactly the same way!!!

Any more thoughts?

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
avatar image
0

Answer by anarchyABC · Jun 09, 2011 at 07:45 PM

Okay, just so I solved my problem: I had conflicting scripts hanging around my project, from when I was experimenting with which scripts would work at the toggling. I deleted all unnecessary scripts and the above java script did the job, thanks Meltdown!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

how do you toggle the visibility of child objects with a mouse over? 1 Answer

Problem is "renderer.isVisible" 3 Answers

Toggle Visibility 1 Answer

How to make collision visible in final game? 1 Answer

Disappearing GUI 2 Answers


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