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.

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.

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?

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!