public void ItemGifted(ItemController.Type typeOfItem) { Vector2 effectPosition = new Vector2(transform.position.x, transform.position.y + 0.5f); GameObject effect = Instantiate(celebrationEffect, effectPosition, Quaternion.identity); GameObject itemEffect = Instantiate(itemAnimationEffect, transform.position, Quaternion.identity); itemEffect.transform.Find("Item Sprite").gameObject.GetComponent <SpriteRenderer>().sprite = GameController.instance.playerItemsManager.GetSpriteForType(typeOfItem); switch (typeOfItem) { case ItemController.Type.FOOD: food += 2f; food = Mathf.Max(0f, Mathf.Min(6f, food)); break; case ItemController.Type.MEDICINE: health += 2f; health = Mathf.Max(0f, Mathf.Min(6f, health)); break; case ItemController.Type.TOY: happy += 1.5f; happy = Mathf.Max(0f, Mathf.Min(6f, happy)); break; } GameController.instance.HUD.UpdatePanels(); }
public void UseItem(ItemController.Type itemType) { if (GameController.instance.pet.IsPlayerCloseToPet()) { GameController.instance.pet.ItemGifted(itemType); SubstractItem(itemType); SoundManager.instance.PlaySingle(useItemSound); } }
int GetIndexOfItemType(ItemController.Type itemType) { for (int i = 0; i < itemKeys.Length; i++) { if (itemKeys[i] == itemType) { return(i); } } return(-1); }
IEnumerator SpawnItem() { state = SpawnPointState.SPAWNING; int randomItemIndex = Random.Range(0, 3); ItemController itemController = (ItemController)Instantiate(GameController.instance.itemPrefab, new Vector2(0f, 0f), Quaternion.identity).GetComponent <ItemController>(); ItemController.Type itemType = (ItemController.Type)randomItemIndex; itemController.transform.SetParent(this.transform, false); itemController.Init(itemType); state = SpawnPointState.WAITING; yield break; }
public void AddItem(ItemController.Type itemType) { SoundManager.instance.PlaySingle(pickupItemSound); if (items.ContainsKey(itemType)) { items[itemType]++; } else { items.Add(itemType, 1); } itemKeys = items.Keys.ToArray(); currentItemTypeSelectedIndex = GetIndexOfItemType(itemType); GameController.instance.HUD.UpdateCurrentItemTypeSelected(); }
public void SubstractItem(ItemController.Type itemType) { if (items.ContainsKey(itemType) && items[itemType] > 0) { items[itemType]--; if (items[itemType] == 0) { items.Remove(itemType); itemKeys = items.Keys.ToArray(); if (itemKeys.Length == 0) { currentItemTypeSelectedIndex = -1; } else { currentItemTypeSelectedIndex = 0; } } } }
public Sprite GetSpriteForType(ItemController.Type type) { Sprite sprite = null; switch (type) { case ItemController.Type.MEDICINE: sprite = GameController.instance.medicine; break; case ItemController.Type.FOOD: sprite = GameController.instance.food; break; case ItemController.Type.TOY: sprite = GameController.instance.toy; break; case ItemController.Type.GEM: sprite = GameController.instance.gem; break; } return(sprite); }