Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by lancer · Aug 14, 2013 at 01:14 AM · javascriptguiinventory

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?

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image lancer · Aug 14, 2013 at 01:25 AM 0
Share

Am I missing anything? I've been at this for hours.

avatar image cdrandin · Aug 14, 2013 at 02:05 AM 0
Share

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.

avatar image lancer · Aug 14, 2013 at 02:10 AM 0
Share

I'm not getting any feed back from the buttons at all.

avatar image vexe · Aug 14, 2013 at 07:40 AM 0
Share

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)

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Adding Item object to Inventory List 0 Answers

How to simplify my Equipment method? 1 Answer

Is there any easy way to keep buttons inside of box? (c#) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges