Hey to everybody,
i searched but i can’t find the answer to this question, maybe because my english isn’t verry good acctualy (germanman).
Would be nice if somebody could help me out.
here what i want to do:
//i want to pass an arument to function AddItem:
using UnityEngine;
using System.Collections;
public class PickUpItem : MonoBehaviour {
public static bool pickUpItem = false;
private int chooseRandomItem = 0;
public int countItemsToPickUp;
private int countItemsPickedUp;
// Use this for initialization
void Start () {
countItemsPickedUp = 0;
}
// Update is called once per frame
void Update () {
}
void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == “Player”)
{
if (pickUpItem)
{
chooseRandomItem = Random.Range( 1, 3);
countItemsPickedUp ++;
switch (chooseRandomItem)
{
case 1:
Inventory.AddItem(1);
break;
case 2:
Inventory.AddItem(2);
break;
case 2:
Inventory.AddItem(3);
break;
}
if (countItemsPickedUp >= countItemsToPickUp)
{
Destroy(gameObject);
}
}
}
}
}
//in another script:
(…)
void AddItem(int id)
{
foundInventoryItemSlot = false;
for (int i = 0; i < inventory.Count; i++)
{
if (inventory*.itemID == id)*
{
for (int j = 0; j < database.items.Count; j++)
{
if (database.items[j].itemID == id)
{
if (stack*.stackCount < database.items[j].itemInventoryStack)*
{
stack*.stackCount += 1;*
}
foundInventoryItemSlot = true;
}
}
break;
}
}
if (!foundInventoryItemSlot)
{
for (int i = 0; i < inventory.Count; i++ )
{
if (inventory*.itemID == -1)*
{
for (int j = 0; j < database.items.Count; j++)
{
if (database.items[j].itemID == id)
{
inventory = database.items[j];
stack*.stackCount = 1;*
}
}
break;
}
}
}
}
(…)
Thanks in advance.