- Home /
Question by
DarkArtsProdigy · Jan 26, 2014 at 04:17 AM ·
javascriptprogramming
Anyway to complete this action?
I tweaked this code a bit and almost have it working.The dropdown menu appears and all but I would like to be able to change the skybox when ever a new option is chosen. Here's what i have but Unity is creating a new button rather than complete the action on the option chosen.
var sky1 : Material;
var sky2 : Material;
var sky3 : Material;
//global variables for settings
var showList : boolean = false;
static var listEntrySelected : int;
static var listEntry : int = 2;
static var defaultEntryNumber : int = 0;
var generalListStyle : GUIStyle = new GUIStyle();
//dropdown menu content
var listColours : GUIContent[]; listColours = new GUIContent[9];
listColours[0] = new GUIContent("Select Sky");
listColours[1] = new GUIContent("Clear Day");
listColours[2] = new GUIContent("Sunny w/ Clouds");
listColours[3] = new GUIContent("Cloudy");
listColours[4] = new GUIContent("Starry Night");
listColours[5] = new GUIContent("Night w/ Moon");
listColours[6] = new GUIContent("Outer Space");
listColours[7] = new GUIContent("Asteroid Belt");
listColours[8] = new GUIContent("Fire Planet");
generalListStyle.padding.left = generalListStyle.padding.right = generalListStyle.padding.top = generalListStyle.padding.bottom = 4;
var dropdownListHash : int = "DropdownList".GetHashCode();
// List(Rect(0,0,100,100), false, 0, GUIContent("Select Colour"), listColours "button", "box", generalListStyle)
function List(position : Rect, expandList : boolean, listEntry : int, defaultListEntry : GUIContent, listToUse : GUIContent[], buttonStyle : GUIStyle, boxStyle : GUIStyle, listStyle : GUIStyle)
{
controlID = GUIUtility.GetControlID(dropdownListHash, FocusType.Passive);
var done : boolean = false;
if(Event.current.GetTypeForControl(controlID) == EventType.mouseDown)
{
if (position.Contains(Event.current.mousePosition))
{
GUIUtility.hotControl = controlID;
showList = !showList;
}
}
if(Event.current.GetTypeForControl(controlID) == EventType.mouseDown && !position.Contains(Event.current.mousePosition))
{
GUIUtility.hotControl = controlID;
}
GUI.Label(position, defaultListEntry, buttonStyle);
if(expandList)
{
//list rectangle
var listRect : Rect = new Rect(position.x, position.y-235, position.width, listStyle.CalcHeight(listToUse[0], 1.0f) * listToUse.Length);
GUI.Box(listRect, "", boxStyle);
listEntrySelected = GUI.SelectionGrid(listRect, listEntrySelected, listToUse, 1, listStyle);
listEntry = listEntrySelected;
if(listEntrySelected != defaultEntryNumber && !position.Contains(Event.current.mousePosition))
{
GUIUtility.hotControl = controlID;
showList = !showList;
defaultEntryNumber = listEntrySelected;
}
}
}
function OnGUI()
{
List(Rect(250, 805, 110, 20), showList, listEntry, GUIContent(listColours[listEntrySelected].text), listColours, "button", "box", generalListStyle);
if (GUILayout.Button ("Clear Day")){
RenderSettings.skybox = sky2;
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Too many bugs 0 Answers
What is a good unityscript writing program? 1 Answer