2022-05-14 15:50:57 -04:00

56 lines
1.5 KiB
C#

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() {
// if(EventSystem.current.IsPointerOverGameObject()){
// hoverObj.SetActive(true);
// }else{
// 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 && player.OnUpgrade(this)){
imgs[lvlUnlocked].sprite = unlockedSprite;
lvlUnlocked++;
if(lvlUnlocked < imgs.Length){
costTxt.text = cost[lvlUnlocked].ToString();
}else{
costTxt.text = "--";
}
return true;
}
return false;
}
}