mirror of
https://github.com/DerTyp7/fps-citybuild-unity.git
synced 2025-10-30 04:27:09 +01:00
ResourceText
This commit is contained in:
@@ -7,4 +7,12 @@ public abstract class Building : MonoBehaviour
|
|||||||
public string title = "New Building";
|
public string title = "New Building";
|
||||||
public string description = "A cool new building";
|
public string description = "A cool new building";
|
||||||
|
|
||||||
|
public enum BuildingType
|
||||||
|
{
|
||||||
|
Housing,
|
||||||
|
Storage,
|
||||||
|
Decoration
|
||||||
|
}
|
||||||
|
|
||||||
|
public BuildingType buildingType;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public class HouseBuildingScript : Building
|
|||||||
{
|
{
|
||||||
title = "House";
|
title = "House";
|
||||||
description = "A place to live in";
|
description = "A place to live in";
|
||||||
|
buildingType = BuildingType.Housing;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ public class StorageBuilding : Building
|
|||||||
[SerializeField] private List<Item> inventory = new List<Item>();
|
[SerializeField] private List<Item> inventory = new List<Item>();
|
||||||
public int inventorySpace;
|
public int inventorySpace;
|
||||||
|
|
||||||
|
public void Start()
|
||||||
|
{
|
||||||
|
buildingType = BuildingType.Storage;
|
||||||
|
}
|
||||||
public void Add(Item item)
|
public void Add(Item item)
|
||||||
{
|
{
|
||||||
if(GetFreeSpace() >= item.count)
|
if(GetFreeSpace() >= item.count)
|
||||||
|
|||||||
35
Assets/Scripts/ResourceUiTextScript.cs
Normal file
35
Assets/Scripts/ResourceUiTextScript.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/ResourceUiTextScript.cs.meta
Normal file
11
Assets/Scripts/ResourceUiTextScript.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fcb96c8b7ecf3554ab9aea050b13d5b1
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -5,13 +5,13 @@ using UnityEngine;
|
|||||||
public class ResourceManager: MonoBehaviour
|
public class ResourceManager: MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private GameObject[] storageBuildings;
|
[SerializeField] private GameObject[] storageBuildings;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
storageBuildings = GameObject.FindGameObjectsWithTag("StorageBuilding");
|
storageBuildings = GameObject.FindGameObjectsWithTag("StorageBuilding");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (Input.GetKeyDown(KeyCode.K))
|
if (Input.GetKeyDown(KeyCode.K))
|
||||||
@@ -30,7 +30,7 @@ public class ResourceManager: MonoBehaviour
|
|||||||
{
|
{
|
||||||
GetAllResources();
|
GetAllResources();
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<Item> GetAllResources()
|
public List<Item> GetAllResources()
|
||||||
|
|||||||
@@ -5,18 +5,19 @@ using UnityEngine.UI;
|
|||||||
|
|
||||||
public class TimeTextScript : MonoBehaviour
|
public class TimeTextScript : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private GameObject GamerManager;
|
private GameObject GameManager;
|
||||||
|
|
||||||
private string timeStr = "";
|
private string timeStr = "";
|
||||||
private Text timeText;
|
private Text timeText;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
GameManager = GameObject.Find("GameManager");
|
||||||
timeText = GetComponent<Text>();
|
timeText = GetComponent<Text>();
|
||||||
}
|
}
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
timeStr = GamerManager.GetComponent<TimeManager>().GetTimeString();
|
timeStr = GameManager.GetComponent<TimeManager>().GetTimeString();
|
||||||
timeText.text = timeStr;
|
timeText.text = timeStr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user