drop down dead

Hello.

Can anyone shed any light on what I’m doing wrong??? All I want is for an object to appear when I select the third item in the dropdown list.

var Seabed : GameObject;

private var showList = false;
private var listEntry = 0;
private var list : GUIContent[];
private var listStyle : GUIStyle;
private var picked = false;

function Start () {
    Seabed.SetActiveRecursively(false);	
	
    // Make some content for the popup list
    list = new GUIContent[5];
    list[0] = new GUIContent("something");
    list[1] = new GUIContent("something");
    list[2] = new GUIContent("something");
    list[3] = new GUIContent("THIS");
    list[4] = new GUIContent("something");
    
    // Make a GUIStyle that has a solid white hover/onHover background to indicate highlighted items
    listStyle = new GUIStyle();
    listStyle.normal.textColor = Color.white;
    var tex = new Texture2D(2, 2);
    listStyle.hover.background = tex;
    listStyle.onHover.background = tex;
    listStyle.padding.left = listStyle.padding.right = listStyle.padding.top = listStyle.padding.bottom = 4;
}

function OnGUI () {
    if (Popup.List (Rect(200, 200, 100, 20), showList, listEntry, GUIContent(list[listEntry].text), list, listStyle)) {
        picked = true;
    }
    if(list[listEntry] == 3) { 
    Seabed.SetActiveRecursively(true);
  } 
}

shouldn’t it be

== “THIS”

not

== 3

I just tried it with “THIS”

but the object still doesn’t appear… :cry:

try
== list[3]

or

listEntry == 3

Thanks gobbledegeek!

I have it working with one object, but doesn’t work with two. Also doesn’t work as a toggle, which is to be expected, but I’d like to make it work. This is a good start though. Any advise on how to code the logic?

At the moment if “THIS” is clicked the corresponding object appears, but when “THAT” is clicked, the “THAT” object appears and makes “THIS” object disappear, and vice-versa. So effectively the combination of the two selected fields toggle between the two objects. When any of the “something” fields are selected, both objects disappear. How do I keep them on screen, unless their corresponding button is clicked again?

Thanks again!

var Seabed : GameObject;
var UpperMaastr : GameObject;


private var showList = false;
private var listEntry = 0;
private var list : GUIContent[];
private var listStyle : GUIStyle;
private var picked = false;

function Start () {
    Seabed.SetActiveRecursively(false);
    UpperMaastr.SetActiveRecursively(false);	
	
    // Make some content for the popup list
    list = new GUIContent[5];
    list[0] = new GUIContent("something");
    list[1] = new GUIContent("THAT");
    list[2] = new GUIContent("something");
    list[3] = new GUIContent("THIS");
    list[4] = new GUIContent("something");
    
    // Make a GUIStyle that has a solid white hover/onHover background to indicate highlighted items
    listStyle = new GUIStyle();
    listStyle.normal.textColor = Color.white;
    var tex = new Texture2D(2, 2);
    listStyle.hover.background = tex;
    listStyle.onHover.background = tex;
    listStyle.padding.left = listStyle.padding.right = listStyle.padding.top = listStyle.padding.bottom = 4;
}

function OnGUI () {
    if (Popup.List (Rect(200, 200, 100, 20), showList, listEntry, GUIContent(list[listEntry].text), list, listStyle)) {
        picked = true;
    }
    if (list[listEntry] == list[1]) { 
    Seabed.SetActiveRecursively(!Seabed.active);
    } 
    
    if (list[listEntry] == list[3]) { 
   	UpperMaastr.SetActiveRecursively(!UpperMaastr.active);
    }
}

sorry for the bump guys, but I feel like I’m almost there…

I think the problem is with the first if statement which defines whether the item is picked or not, but not which item is picked. At the moment the !active toggles the previous object, not the object itself. So if [1] is visible and I click on menu item [3], then [3] becomes visible and [1] invisible. Then if I click item [2], it will become visible turning [3] invisible… etc. I need it so that once an item [1] or [2] or [3] is clicked, it remains visible until it is clicked again, irrespective of the other items visibility. Hope that makes sense. Cheers

//surfaces
var Seabed : GameObject;
var Miocene : GameObject;
var Paleocene : GameObject;
var UpperMaastr : GameObject;

private var showList = false;
private var listEntry = 0;
private var list : GUIContent[];
private var listStyle : GUIStyle;
private var picked = false;

function Start () {
        Seabed.SetActiveRecursively(false);
 	Miocene.SetActiveRecursively(false);
	Paleocene.SetActiveRecursively(false);
	UpperMaastr.SetActiveRecursively(false);

    // Make some content for the popup list
    list = new GUIContent[4];
    list[0] = new GUIContent("Seabed");
    list[1] = new GUIContent("Miocene");
    list[2] = new GUIContent("Paleocene");
    list[3] = new GUIContent("UpperMaastricht");
    
    // Make a GUIStyle that has a solid white hover/onHover background to indicate highlighted items
    listStyle = new GUIStyle();
    listStyle.normal.textColor = Color.white;
    var tex = new Texture2D(2, 2);
    listStyle.hover.background = tex;
    listStyle.onHover.background = tex;
    listStyle.padding.left = listStyle.padding.right = listStyle.padding.top = listStyle.padding.bottom = 4;
}

function OnGUI () {
    if (Popup.List (Rect(200, 200, 100, 20), showList, listEntry, GUIContent("SURFACES"), list, listStyle)) {
    picked = true;
    }
    
    if (list[listEntry] == list[0]) { 
    Seabed.SetActiveRecursively(!Seabed.active);
    }
    
    if (list[listEntry] == list[1]) { 
    Miocene.SetActiveRecursively(!Miocene.active);
    }
    
    if (list[listEntry] == list[2]) { 
    Paleocene.SetActiveRecursively(!Paleocene.active);
    }
    
    if (list[listEntry] == list[3]) { 
   	UpperMaastr.SetActiveRecursively(!UpperMaastr.active);
    }
    
}