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 szaagi · Dec 27, 2013 at 04:38 PM · guiinventorygui button

Gui button and iventory problem

I try to do a gui button for my inventory. And there's a problem after click sound play but description texture don't show :(

Any ideas why?

 ////////// item //////////
 
 
 var inventoryIcon:Texture2D;
 var descriptionTex:Texture2D;
 var obj:GameObject;
 public var info:AudioClip;
 public var nul:AudioClip;
 function OnMouseDown(){
     if(!collider.isTrigger){
     
         var playersinv=FindObjectOfType(InventoryJS);    
         playersinv.AddItem(this.transform);    
         collider.isTrigger = true;    
     }else{
     obj.audio.PlayOneShot(nul);
     
     }
 
     }
 
 
 ///////////Inventory///////////
 
 
 var Contents:Transform[];
 
 function AddItem(Item:Transform){
     var newContents=new Array(Contents);
     newContents.Add(Item);
     Debug.Log(Item.name+" Has been added to inventroy");
     Contents=newContents.ToBuiltin(Transform);
 }
 
 
 ///////////Gui/////////////
 
 
 private var windowPosition:Vector2=Vector2(0,0);
 private var windowSize:Vector2=Vector2(1000.0,1000.0);
 var itemIconSize:Vector2=Vector2(100.0,100.0);
 var back:Texture;
 private var pressed:boolean=false;
 private var visible:boolean=false;
 private var lastTooltip :String = "";
 var updateListDelay=1.0;
 var UpdatedList:Transform[];
 var lastUpdate = 1.0;
 var associatedInventory:InventoryJS;
 var person:CharacterController;
 private var counter = 0;
 
 
 function Update () {
  if(Input.GetKeyDown(KeyCode.Escape)){
      if(pressed == false){
      Screen.lockCursor = false;
      Screen.showCursor = true;
       GetComponent(MouseLook).enabled = false;
     person.GetComponent(MouseLook).enabled = false;
     Crosshair.on = false;
   pressed = true;
   Time.timeScale = 0;
   visible = true;
    }else{
       Screen.lockCursor = true;
       Screen.showCursor = false;
       GetComponent(MouseLook).enabled = true;
     person.GetComponent(MouseLook).enabled  = true;
     Crosshair.on = true;
        visible = false;
     pressed = false;
     Time.timeScale = 1.0;
   }
  }
  }
 function UpdateInventoryList(){
     UpdatedList=associatedInventory.Contents;
 }
 function OnGUI(){
         if(visible&&pressed){
     var currentX=windowPosition.x;
     var currentY=windowPosition.y;
     GUI.DrawTexture(Rect(0,0,Screen.width,Screen.height),back,ScaleMode.StretchToFill);
     for(var i:Transform in UpdatedList){
     var item=i.GetComponent.<ItemJS>();
         if(GUI.Button(Rect(currentX ,currentY,itemIconSize.x,itemIconSize.y),GUIContent (item.inventoryIcon, "tooltip"))){
             GUI.DrawTexture(Rect(Screen.width/2,Screen.height/2,item.descriptionTex.x,item.descriptionTex.y),item.descriptionTex);
             item.audio.PlayOneShot(item.sound);
             lastUpdate=0.0;
         }
         currentX+=itemIconSize.x;
         if(currentX+itemIconSize.x>windowPosition.x+windowSize.x){
             currentX=windowPosition.x;
             currentY+=itemIconSize.y;
             if(currentY+itemIconSize.y>windowPosition.y+windowSize.y){
                 return;
                 }
             }
         }
         
         if(GUI.Button(Rect(0, Screen.height/2+(Screen.height/2-30), Screen.width/2-1, 29), "Quit Game")){
         Application.Quit();
         }
         if(GUI.Button(Rect(Screen.width/2, Screen.height/2+(Screen.height/2-30), Screen.width/2-1, 29), "Back To Main Menu")){
         Application.LoadLevel ("menu");
         }
         
         
         
     }
 }
 
 
 function FixedUpdate(){
     if(Time.time>lastUpdate){
         lastUpdate=Time.time+updateListDelay;
         UpdateInventoryList();
     }
 }
Comment
Add comment
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

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

18 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 avatar image avatar image

Related Questions

Mysterious crash involving an array 2 Answers

Knowing when a button is pressed, not released. 2 Answers

loop GUI Buttons doesn`t respond 0 Answers

Adding Item object to Inventory List 0 Answers

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