- Home /
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
Your answer

Follow this Question
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