SHARE
TWEET

Untitled

a guest Jan 18th, 2020 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6.  
  7. public class DefenderButton : MonoBehaviour
  8. {
  9.  
  10.      [SerializeField] Defender defenderPrefab;
  11.     int defenderCost;
  12.     GemDisplay gemDisplay;
  13.  
  14.     private void Awake()
  15.     {
  16.         defenderCost = defenderPrefab.GetGemCost();
  17.         gemDisplay = FindObjectOfType<GemDisplay>();
  18.     }
  19.     private void Start()
  20.     {
  21.        
  22.         LabelButtonWithCost();
  23.          
  24.  
  25.     }
  26.     private void Update()
  27.     {
  28.         if (gemDisplay.HaveEnoughStars(defenderCost))
  29.         {
  30.             DefenderColorWhite();
  31.         }
  32.         else if(!gemDisplay.HaveEnoughStars(defenderCost))
  33.         {
  34.             GetComponent<SpriteRenderer>().color = new Color32(22, 16, 16, 255);
  35.         }
  36.     }
  37.  
  38.     private void LabelButtonWithCost()
  39.     {
  40.         Text costText = GetComponentInChildren<Text>();
  41.         if (!costText)
  42.         {
  43.             Debug.LogError(name + " has no cost text, add some!");
  44.         }
  45.         else
  46.         {
  47.            
  48.          costText.text = defenderPrefab.GetGemCost().ToString();
  49.         }
  50.     }
  51.  
  52.     private void DefenderColorWhite()
  53.     {
  54.        
  55.         var buttons = FindObjectsOfType<DefenderButton>();
  56.      
  57.             foreach (DefenderButton button in buttons)
  58.             {
  59.                 button.GetComponent<SpriteRenderer>().color = Color.white;
  60.                
  61.             }
  62.     }
  63.  
  64.     private void OnMouseDown()
  65.     {
  66.  
  67.         FindObjectOfType<DefenderSpawner>().SetSelectecDefender(defenderPrefab);
  68.  
  69.     }
  70.  
  71.  
  72.  
  73. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top