Hi All,
I’ve got this inventory from someone else and its working perfect, but now i want to use it in a way that it checks if there are a certain amount of items in it, to open a door, for example a Key (but in some cases i want it to check if there are 4 or 5 items in the inventory. I’ve spend about 2 hours on it with a friend but we can’t seem to get it right.
Inventory script:
var numberOfSlots=24;
var numberOfColumns=4;
var textureSize=64;
var showBag=true;
public var items : Item[];
private var windowRect: Rect;
function Start(){
var slots : float=numberOfSlots;
var cols : float=numberOfColumns;
items=new Item[numberOfSlots];
var rows=Mathf.Ceil(slots / cols);
var width = textureSize * numberOfColumns + 20;
var height = textureSize * rows + 30;
windowRect = Rect((Screen.width - width) / 2, (Screen.height - height) / 2, width, height);
}
function Update(){
if(Input.GetKeyDown("b")) showBag=!showBag;
//logic code here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
public function check(oName:String)
{
for(var i = 0; i < items.length; i++)
{
if(items*)*
{
if(items*.name == oName)*
{
return true;
}else{
return false;
}
}
}
}
function OnGUI(){
* if(showBag){*
* GUI.depth = 0;*
* CreateWindow();*
* }*
}
function DragInventory(windowID:int){
* for(var i=0; i< numberOfSlots; i++){*
* var y=Mathf.Floor(i / numberOfColumns);*
_ var x=i - y * numberOfColumns;
var rect = Rect(textureSize * x + 10, textureSize * y + 20, textureSize, textureSize);
* var texture : Texture2D;*
if(items)texture = items*.texture;
var slot = GUI.Button(rect, texture);*_
* if(rect.Contains(Event.current.mousePosition)){*
_ if(items == null && DragDrop.item != null && Input.GetMouseButtonUp(0)){
items = DragDrop.item;
//if(items*.gameObject){
//Destroy(items.gameObject);
//items.gameObject=null;
//}
}*_
_ if(Input.GetMouseButtonUp(1) && items && DragDrop.toolSelected){
* var go=new GameObject.CreatePrimitive(PrimitiveType.Cube);
go.renderer.material.mainTexture=items.texture;
go.AddComponent(Rigidbody);
go.AddComponent(AddToInventory);
var s=go.GetComponent(AddToInventory);
s.item=items;
items = null;
DragDrop.toolSelected=false;
}*_
* if(slot){}*
* }*
* }*
GUI.DragWindow();
}
function AddItem(item : Item){
* for(var i=0; i< numberOfSlots; i++){*
_ if(!items*){
items=item;
if(item.gameObject)Destroy(item.gameObject);
return;
}
}
}*_
function CreateWindow()
{
* GUI.BeginGroup(windowRect);*
* windowRect = GUI.Window(0, windowRect, DragInventory, “Inventory”);*
* GUI.EndGroup();*
}
Can anyone help out? There are more scripts in this package, but for as far as my knowledge goes you dont need those, else ask me.
If you are willing to help me out do you want to work with sample items apple, banana, so i can recall everything perfectly.
Thanks in Advance.
Why doesnt the code section work properly :(
– MrcDesign