public UIStatIndicator(Slider component, Attribute attribute, Manny.Manny manny) { _slider = SliderUtil.SetSliderBackground(component); _attribute = attribute; _text = _slider.GetComponentInChildren <Text>(); _manny = manny; }
/// <summary> /// This function is called when the player buys an item. /// It updates the specific attribute en decreases the player's money. /// </summary> /// <param name="manny">The manny object of the game</param> public void Buy(Manny.Manny manny) { if (manny.Attribute.GetAttribute(Attribute) > 100 - Value) { manny.Attribute.SetAttribute(Attribute, 101); } else { manny.Attribute.IncrementAttribute(Attribute, Value); } manny.Attribute.IncrementAttribute(Attribute.Coins, -Cost); }
/// <summary> /// Fill the prefab with the information from the shopitem /// </summary> public void Init() { _manny = FindObjectOfType <Manny.Manny>(); _shop = FindObjectOfType <ShopController>(); Icon.texture = Item.Icon; Icon.color = Item.Attribute == Attribute.Food ? new Color32(18, 178, 112, 255) : new Color32(26, 118, 175, 255); Name.text = Item.Name; Description.text = Item.Description; Gain.text = "+" + Item.Value + " " + (Item.Attribute == Attribute.Food ? "Eten" : "Drinken"); Cost.text = Item.Cost.ToString(); var emis = ParticleSystem.emission; emis.SetBurst(0, new ParticleSystem.Burst(0.0f, Item.Cost)); }
// Use this for initialization private void Start() { var y = -75f; _manny = FindObjectOfType <Manny.Manny>(); UpdateCoins(); // Loop through the ShopItem array and create a ShopItemPrefab with each one of them foreach (var item in Items) { var obj = Instantiate(Item, transform).GetComponent <ShopItemPrefab>(); obj.Item = item; obj.GetComponentInChildren <Button>().GetComponent <Image>().sprite = item.Attribute == Attribute.Food ? BtnFood : BtnDrink; obj.Init(); var rect = obj.GetComponent <RectTransform>().rect; _prefabHeight = rect.height; obj.transform.localPosition = new Vector2(rect.width / 2, y); y -= _prefabHeight; } }
/// <summary> /// Makes the reference to the Manny instance /// </summary> /// <param name="manny">Manny main instance</param> public void SetInstance(Manny.Manny manny) { _manny = manny; Slider = SliderUtil.SetSliderBackground(Slider); Slider.maxValue = 5; }