- Home /
Question by
pkiriakou · Apr 16, 2013 at 09:20 AM ·
javascriptlistpopup
PopupList always returns the 0 listEntry. what am I doing wrong?
I have used the code for the popup list from http://wiki.unity3d.com/index.php?title=PopupList. created 2 files a javascript "pop.js" and c# file "Popup.cs". I am populating the list with a list from my resources folder with collada files as you can see from my code below. I get it to show me the list with the resources, but whatever I click on, it always returns the first item form the list. Can you help me? thanks
private var showList = false;
private var listEntry = 0;
private var list : GUIContent[];
private var listStyle : GUIStyle;
private var picked = false;
var i : int = 0;
var info = new DirectoryInfo(".\\Assets\\Resources\\");
var fileInfo = info.GetFiles();
var temp : String;
function Start () {
list = new GUIContent[4];
for (file in fileInfo) {
if(file.Extension==".dae"){
print((file.Name));
list[i] = new GUIContent(file.Name);
temp = temp+" "+i+":"+file.Name+"";
i++;
}
}
// 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);
var colors = new Color[4];
for (color in colors) color = Color.white;
tex.SetPixels(colors);
tex.Apply();
listStyle.hover.background = tex;
listStyle.onHover.background = tex;
listStyle.padding.left = listStyle.padding.right = listStyle.padding.top = listStyle.padding.bottom = 4;
}
function loadResource(selection){
print("Selection: "+selection);
//var object : GameObject = Instantiate(Resource.Load(selection));
}
function OnGUI () {
print(listEntry);
if (Popup.List (Rect(50, 100, 200, 20), showList, listEntry, GUIContent("Please Choose Object!"), list, listStyle)) {
picked = true;
print(listEntry);
loadResource(list[listEntry].text);
}
if (picked) {
GUI.Label (Rect(50, 70, 400, 20), "You have selected " + list[listEntry].text + "!");
//loadResource(list[listEntry].text);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613100422im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Java Script command list 3 Answers
FindIndex in a List 1 Answer
How to make a List Constructor? 1 Answer