TheMuseumProject/Assets/Scripts/ConstructSystem/ConstructMaker.cs

48 lines
1.0 KiB
C#

using TMPro;
using UnityEngine;
public class ConstructMaker : ConstructBase
{
[SerializeField] private string resourceName = "";
[SerializeField] private float resourceMax;
[SerializeField] private float resourceRate;
private float resource;
private TMP_Text resourceIndicator;
private void Start()
{
resourceIndicator = transform.Find("ResourceIndicator").GetComponent<TMP_Text>();
}
private void Update()
{
if (resource != resourceMax)
{
resource = Mathf.Clamp(resource + resourceRate * Time.deltaTime, 0f, resourceMax);
resourceIndicator.SetText(resourceName + ":\n" + Mathf.FloorToInt(resource));
}
}
public void SetProperties(string name, float max, float rate)
{
resourceName = name;
resourceMax = max;
resourceRate = rate;
}
public new float Interact()
{
var amount = resource;
resource = 0f;
return amount;
}
public string GetResource()
{
return resourceName;
}
}