// utils public GameObject instanciateItem(Item.Element type) { switch (type) { case Item.Element.MEAT: return(Instantiate(meatPrefab)); case Item.Element.APPLE: return(Instantiate(applePrefab)); case Item.Element.FISH: return(Instantiate(fishPrefab)); case Item.Element.SHIELD: return(Instantiate(shieldPrefab)); case Item.Element.SWORD: return(Instantiate(swordPrefab)); case Item.Element.BOOT: return(Instantiate(bootPrefab)); case Item.Element.DIAMOND: return(Instantiate(diamondPrefab)); case Item.Element.COIN: return(Instantiate(coinPrefab)); case Item.Element.CAN: return(Instantiate(canPrefab)); case Item.Element.LINT: return(Instantiate(lintPrefab)); case Item.Element.BONE: return(Instantiate(bonePrefab)); case Item.Element.ROCK: return(Instantiate(rockPrefab)); default: return(null); } }
public Item.Element[] getInventory() { Item.Element[] result = new Item.Element[3]; for (int i = 0; i < 3; i++) { if (i < inventory.Count) { result[i] = inventory[i]; } else { result[i] = Item.Element.NONE; } } return(result); }
public void PushFrontElement(Item.Element item) { for (int i = 0; i < 3; i++) { if (slots[i] == Item.Element.NONE) { slots[i] = item; return; } } int moncul = Random.Range(0, 3); inventory.Insert(0, slots[moncul]); slots[moncul] = item; }
public Item.Element popItem(int index) { Item.Element item = Item.Element.NONE; if (index >= 0 && index < 3 && slots[index] != Item.Element.NONE) { item = slots[index]; if (inventory.Count > 0) { slots[index] = inventory[0]; inventory.RemoveAt(0); } else { slots[index] = Item.Element.NONE; } } return(item); }
private bool createObjectAroundPlayer(Item.Element item) { if (item != Item.Element.APPLE && item != Item.Element.FISH && item != Item.Element.MEAT && item != Item.Element.NONE) { for (int i = 0; i < 100; i++) { Vector2 itemPositionTmp; itemPositionTmp = (Vector2)transform.position + Random.insideUnitCircle * _circleSizePopObject * SizeTarget; RaycastHit2D oclusion = Physics2D.CircleCast(itemPositionTmp, 0.5F, Forward, 0, 1 << LayerMask.NameToLayer("Map")); float distancePlayerObject = Vector2.Distance((Vector2)transform.position, itemPositionTmp); if (!oclusion && distancePlayerObject > SizeTarget * 2) { GameObject newItem = Inventory.Instance.instanciateItem(item); newItem.transform.position = itemPositionTmp; newItem.GetComponent <Item> ().cooldownSensitive = true; return(true); } } } return(false); }
// Update is called once per frame void Update() { if (Inventory.Instance == null) { return; } for (int i = 0; i < _slots.Length; ++i) { if (i < Inventory.Instance.getSlots().Length && Inventory.Instance.getSlots()[i] != Item.Element.NONE) { // TODO: Attach sprite Item.Element element = Inventory.Instance.getSlots()[i]; _slots[i].sprite = Inventory.Instance.getSprite(element); _slots[i].color = Color.white; } else { _slots[i].sprite = null; _slots[i].color = Color.clear; } } for (int i = 0; i < _inventory.Length; ++i) { if (i < Inventory.Instance.getInventory().Length && Inventory.Instance.getInventory()[i] != Item.Element.NONE) { // TODO: Attach sprite Item.Element element = Inventory.Instance.getInventory()[i]; _inventory[i].sprite = Inventory.Instance.getSprite(element); _inventory[i].color = Color.white; } else { _inventory[i].sprite = null; _inventory[i].color = Color.clear; } } }
public Sprite getSprite(Item.Element type) { return(sprites[(int)type - 1]); }