- Home /
Script Not Working
I'm making an inventory system, but when I click any of the buttons it doesn't say which button was clicked. It is programed to say in the log what button was pressed, but never says anything, here is the script:
#pragma strict
var ShopName : String;
var Enabled : boolean;
var BackgroundTexture : Texture;
var Items : String[];
var ItemTextures : Texture[];
private var shopSize : Rect = Rect(Screen.width / 2,0,600,800);
private var scrollPosition : Vector2;
function Start () {
shopSize = Rect(Screen.width / 2 - 300,0,600,Screen.height);
}
static var ItemImages : Texture[];
function Update () {
ItemImages = ItemTextures;
}
function OnInspectorUpdate(){
}
function enable(i : boolean){
if(i == true){
Enabled = true;
}
if(i == false){
Enabled = false;
}
}
function OnGUI(){
if(Enabled == true){
shopSize = GUILayout.Window(200, shopSize, ShopWin, ShopName);
}
}
function ShopWin (windowID : int) {
scrollPosition = GUILayout.BeginScrollView (scrollPosition, false, true, GUILayout.Width(80),GUILayout.Height(Screen.height - 100));
GUILayout.BeginVertical();
for(var i:int =0;i<Items.length;i++){
if(ItemTextures.Length > 0){
if(GUILayout.Button(ItemTextures[i], GUILayout.Width(60), GUILayout.Height(60)))
{
Debug.Log("Clicked: " + Items[i]);
}
}
else{
if(GUILayout.Button(Items[i].ToString(), GUILayout.Width(60), GUILayout.Height(60)))
{
Debug.Log("Clicked: " + Items[i]);
}
}
}
GUILayout.EndVertical();
GUI.DragWindow();
GUILayout.EndScrollView();
}
Does anyone see what is wrong?
Are you getting any feed back at all from your GUI buttons? Try clicking all over the screen to see if your debug print catches anything.
You have a "ShopWin(int)" function, why are you calling it without parameters in the line "shopSize = GUILayout.Window(200, shopSize, ShopWin, ShopName);"
? - And not that it's related, but there are a couple of redundancies in your code, namely your "enable" function, it could be a one-liner: "Enabled = i;"
- And in your OnGUI, you don't need to say if (Enabled == true), you could just say if (Enabled)