Files
fps-citybuild-unity/Assets/Scripts/ResourceUiTextScript.cs
2021-10-01 11:11:58 +02:00

36 lines
845 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ResourceUiTextScript : MonoBehaviour
{
private ResourceManager resourceManager;
private string str = "";
private TMPro.TextMeshProUGUI textResource;
private void Start()
{
resourceManager = GameObject.Find("GameManager").GetComponent<ResourceManager>();
textResource = GetComponent<TMPro.TextMeshProUGUI>();
}
void Update()
{
List<Item> inventory = new List<Item>();
inventory = resourceManager.GetAllResources();
str = "";
foreach(Item i in inventory)
{
if(i != null)
{
str += i.count.ToString() + " " + i.name + "\n";
}
}
textResource.text = str;
}
}