public void BeginPlacingObject(DefenseContainer defense)
    {
        float price = defense.price;

        if (CurrencyManager.instance.Weed >= price)
        {
            if (isPlacing)
            {
                CancelPlacing();
            }
            isPlacing      = true;
            currentOutline = Instantiate(defense.outlineObject) as GameObject;
            defenseToSpawn = defense;
            if (defenseToSpawn.defensePrefab.GetComponent <TargetDefense>() != null &&
                currentOutline.GetComponent <OutlineRangeVisualizer>() != null)
            {
                float range = defenseToSpawn.defensePrefab.GetComponent <TargetDefense>().rangeStat.Value;
                currentOutline.GetComponent <OutlineRangeVisualizer>().DrawRange(range);
            }
            currentOutline.transform.position = outlineSpawnPos.position;
            placeButtonObject.SetActive(true);
            cancelButton.gameObject.SetActive(true);
            Debug.Log("Began placing defense");
        }
        else
        {
            NotificationManager.instance.ShowMessage("Not enough weed!");
        }
    }
 public void InitInfo(DefenseContainer defense)
 {
     ClearInfo();
     iconObject.sprite = defense.icon;
     foreach (string info in defense.info)
     {
         GameObject text = Instantiate(textPrefab) as GameObject;
         text.GetComponent <InfoText>().text.text = info;
         text.transform.SetParent(infoBox.transform);
     }
     placeButton.onClick.RemoveAllListeners();
     placeButton.onClick.AddListener(() => PlaceDefense(defense));
     gameObject.SetActive(true);
 }
Esempio n. 3
0
 private void OnCurrencyChange()
 {
     foreach (Transform child in buttonHolder)
     {
         DefenseButtonData data            = child.GetComponent <DefenseButtonData>();
         DefenseContainer  defense         = data.defense;
         float             currentCurrency = CurrencyManager.instance.Weed;
         Button            btn             = child.GetComponent <Button>();
         ColorBlock        colors          = btn.colors;
         if (defense.price > currentCurrency)
         {
             colors.normalColor = Color.gray;
             btn.interactable   = false;
         }
         else
         {
             colors.normalColor = Color.white;
             btn.interactable   = true;
         }
         btn.colors = colors;
     }
 }
 private void BeginPlacingDefense(DefenseContainer container)
 {
     infoBox.InitInfo(container);
 }
 public void PlaceDefense(DefenseContainer defense)
 {
     DefensePlacement.instance.BeginPlacingObject(defense);
     Hide();
 }