Hello, i have a little Question.
I createt an Inventory Script from a Tutorial. My question is how can i open this when i Press I. And close when i Press I? Can anybody explain me that?
Here is the Script:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class Inventory : MonoBehaviour {
public List<GameObject> Slots = new List<GameObject> ();
public List<Item> Items = new List<Item> ();
public GameObject slots;
ItemDatabase database;
public GameObject tooltip;
public GameObject draggedItemGameObject;
public bool draggingItem = false;
public Item draggedItem;
public int indexOfDraggedItem;
void Update()
{
if (draggingItem)
{
Vector3 posi = (Input.mousePosition - GameObject.FindGameObjectWithTag("Canvas").GetComponent<RectTransform>().localPosition);
draggedItemGameObject.GetComponent<RectTransform>().localPosition = new Vector3(posi.x +15, posi.y -15, posi.z);
}
}
public void showTooltip (Vector3 toolPosition, Item item)
{
tooltip.SetActive (true);
tooltip.GetComponent<RectTransform> ().localPosition = new Vector3 (toolPosition.x + 55, toolPosition.y - 115, toolPosition.z);
tooltip.transform.GetChild (0).GetComponent<Text> ().text = item.itemName;
tooltip.transform.GetChild (1).GetComponent<Text> ().text = item.itemDesc;
}
public void showDraggedItem(Item item, int slotnumber)
{
indexOfDraggedItem = slotnumber;
closeTooltip ();
draggedItemGameObject.SetActive (true);
draggedItem = item;
draggingItem = true;
draggedItemGameObject.GetComponent<Image> ().sprite = item.ItemIcon;
}
public void closeDraggedItem()
{
draggingItem = false;
draggedItemGameObject.SetActive (false);
}
public void closeTooltip()
{
tooltip.SetActive (false);
}
void Start () {
int Slotamount = 0;
database = GameObject.FindGameObjectWithTag ("ItemDatabase").GetComponent<ItemDatabase> ();
int x = -150;
int y = 40;
for (int i = 1; i < 4; i++)
{
for(int k = 1; k< 8; k++)
{
GameObject slot = (GameObject)Instantiate(slots);
slot.GetComponent<SlotScript>().slotNumber = Slotamount;
Slots.Add (slot);
Items.Add (new Item());
slot.transform.parent = this.gameObject.transform;
slot.name = "Slot" + i + "." + k;
slot.GetComponent<RectTransform>().localPosition = new Vector3(x, y, 0);
x = x + 50;
if(k == 7)
{
x = -150;
y = y - 50;
}
Slotamount++;
}
}
addItem (1);
addItem (1);
addItem (2);
addItem (3);
addItem (4);
addItem (5);
}
public void checkIfItemExist(int itemID, Item item)
{
for (int i = 0; i < Items.Count; i++)
{
if(Items*.itemID == itemID)*
-
{*
Items_.itemValue = Items*.itemValue + item.itemValue;
break;
}
else if(i == Items.Count - 1)
{
addItemAtEmptySlot(item);
}
}
}*_
* public void addExistingItem(Item item)*
* {*
* if (item.itemType == Item.ItemType.Konsumgüter) {*
* checkIfItemExist (item.itemID, item);*
* }*
* else*
* addItemAtEmptySlot (item);*
* }*
* void addItem(int id)*
* {*
* for (int i = 0; i < database.items.Count; i++)*
* {*
_ if(database.items*.itemID == id)
{
Item item = database.items;*_
_ if(database.items*.itemType == Item.ItemType.Konsumgüter)
{
checkIfItemExist(id, item);
break;
}
else*
* {
addItemAtEmptySlot(item);
}
}
}
}*_
* void addItemAtEmptySlot(Item item)*
* {*
* for (int i = 0; i < Items.Count; i++)*
* {*
_ if(Items*.itemName == null)
{
Items = item;
break;
}
}
}
}*
By the Way… Sorry for my bad english :o_