using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; using TMPro; public abstract class Upgrade : MonoBehaviour { [SerializeField]protected float[] cost; [SerializeField]protected TMP_Text costTxt; [SerializeField]protected string upgradeName; protected int lvlUnlocked; [SerializeField]protected Sprite unlockedSprite; [SerializeField]protected GameObject hoverObj; [SerializeField]protected Image[] imgs; [SerializeField]protected PlayerController player; private void Start() { lvlUnlocked = 0; costTxt.text = cost[lvlUnlocked].ToString(); } private void Update() { } public void OnPointerEnter(){ if(lvlUnlocked < imgs.Length){ hoverObj.SetActive(true); } } public void OnPointerExit(){ hoverObj.SetActive(false); } public float GetCost(){ return cost[lvlUnlocked]; } public string GetName(){ return name; } public virtual void Activate(){ UpgradeAttempt(); } protected bool UpgradeAttempt(){ if(lvlUnlocked < imgs.Length && GameManager.Instance.OnUpgrade(this)){ imgs[lvlUnlocked].sprite = unlockedSprite; lvlUnlocked++; if(lvlUnlocked < imgs.Length){ costTxt.text = cost[lvlUnlocked].ToString(); }else{ costTxt.text = "--"; } return true; } return false; } }