Files
CityBuilder/Assets/Scripts/TechTooltip.cs

41 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using TMPro;
public class TechTooltip : MonoBehaviour
{
public static TechTooltip Instance { get; private set; }
[SerializeField]
private TextMeshProUGUI techCostText, techDescriptionText, techModText;
private void LateUpdate()
{
transform.position = Input.mousePosition;
}
public void Show(Technology tech)
{
gameObject.SetActive(true);
string cost = string.Join("\n", tech.resourceCosts.Select(c => string.Format("-{0} {1}", c.resourceAmount, c.resourceType)));
string mods = string.Join("\n", tech.techModifiers.Select(m => string.Format("+{0} {1}", m.amount, m.modifier)));
techCostText.text = cost;
techModText.text = mods;
techDescriptionText.text = tech.techDescription;
}
public void Hide()
{
gameObject.SetActive(false);
}
// Start is called before the first frame update
void Awake()
{
gameObject.SetActive(false);
if (Instance != null && Instance != this)
{
Destroy(this.gameObject);
}
else
{
Instance = this;
}
}
}