The fucking 3rd time i had to upload this project to git
This commit is contained in:
28
Assets/Scripts/ConstructSystem/ConstructArea.cs
Normal file
28
Assets/Scripts/ConstructSystem/ConstructArea.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using Player.Information;
|
||||
using UnityEngine;
|
||||
|
||||
public class ConstructArea : ConstructBase
|
||||
{
|
||||
[SerializeField] private string resourceName = "";
|
||||
|
||||
[SerializeField] private float resourceRate;
|
||||
|
||||
[SerializeField] private float radiusEffect;
|
||||
|
||||
private GameObject player;
|
||||
private PlayerStats playerStats;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
player = GameObject.FindGameObjectWithTag("Player");
|
||||
playerStats = player.GetComponent<PlayerStats>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if (Vector3.Distance(player.transform.position, transform.position) <= radiusEffect)
|
||||
playerStats.ConsumeResource(resourceRate * Time.deltaTime, resourceName);
|
||||
}
|
||||
}
|
11
Assets/Scripts/ConstructSystem/ConstructArea.cs.meta
Normal file
11
Assets/Scripts/ConstructSystem/ConstructArea.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d286e9c290eb46609cf5c63860d895a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
32
Assets/Scripts/ConstructSystem/ConstructBase.cs
Normal file
32
Assets/Scripts/ConstructSystem/ConstructBase.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ConstructBase : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private int naniteCost = 1;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
|
||||
// called whenever the player collects the resources from this construct
|
||||
public void Interact()
|
||||
{
|
||||
}
|
||||
|
||||
public int Disassemble()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return naniteCost;
|
||||
}
|
||||
|
||||
public int GetCost()
|
||||
{
|
||||
return naniteCost;
|
||||
}
|
||||
}
|
11
Assets/Scripts/ConstructSystem/ConstructBase.cs.meta
Normal file
11
Assets/Scripts/ConstructSystem/ConstructBase.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83f7334cb0b8146daa47bb6225d1c483
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
48
Assets/Scripts/ConstructSystem/ConstructMaker.cs
Normal file
48
Assets/Scripts/ConstructSystem/ConstructMaker.cs
Normal file
@ -0,0 +1,48 @@
|
||||
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;
|
||||
}
|
||||
}
|
11
Assets/Scripts/ConstructSystem/ConstructMaker.cs.meta
Normal file
11
Assets/Scripts/ConstructSystem/ConstructMaker.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe814975be4c040bb9ca783a86651225
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
85
Assets/Scripts/ConstructSystem/ConstructManager.cs
Normal file
85
Assets/Scripts/ConstructSystem/ConstructManager.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Player.Information;
|
||||
|
||||
public class ConstructManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private bool isMaker = true;
|
||||
|
||||
[SerializeField] private string resourceName = "";
|
||||
|
||||
[SerializeField] private float resourceMax = 50f;
|
||||
|
||||
[SerializeField] private float resourceRate = 1f;
|
||||
|
||||
[SerializeField] private float radiusEffect = 5f;
|
||||
|
||||
private GameObject player;
|
||||
private PlayerStats playerStats;
|
||||
private float resource;
|
||||
|
||||
private TMP_Text resourceIndicator;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
resourceIndicator = transform.Find("ResourceIndicator").GetComponent<TMP_Text>();
|
||||
|
||||
if (isMaker)
|
||||
{
|
||||
resourceIndicator = transform.Find("ResourceIndicator").GetComponent<TMP_Text>();
|
||||
}
|
||||
else
|
||||
{
|
||||
resourceIndicator.enabled = false;
|
||||
player = GameObject.FindGameObjectWithTag("Player");
|
||||
playerStats = player.GetComponent<PlayerStats>();
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if (isMaker)
|
||||
{
|
||||
if (resource != resourceMax)
|
||||
{
|
||||
resource = Mathf.Clamp(resource + resourceRate * Time.deltaTime, 0f, resourceMax);
|
||||
resourceIndicator.SetText(resourceName + ":\n" + Mathf.FloorToInt(resource));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Vector3.Distance(player.transform.position, transform.position) <= radiusEffect)
|
||||
playerStats.ChangeHealth(resourceRate * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
// called whenever the player collects the resources from this construct
|
||||
public float CollectAll()
|
||||
{
|
||||
if (isMaker)
|
||||
{
|
||||
var amount = resource;
|
||||
resource = 0f;
|
||||
return amount;
|
||||
}
|
||||
|
||||
return 0f;
|
||||
}
|
||||
|
||||
public void Disassemble()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
public bool IsMaker()
|
||||
{
|
||||
return isMaker;
|
||||
}
|
||||
|
||||
public string GetResource()
|
||||
{
|
||||
return resourceName;
|
||||
}
|
||||
}
|
11
Assets/Scripts/ConstructSystem/ConstructManager.cs.meta
Normal file
11
Assets/Scripts/ConstructSystem/ConstructManager.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8d47f4cb96974450ac18ad56e19ab56
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
41
Assets/Scripts/ConstructSystem/FoodMakerController.cs
Normal file
41
Assets/Scripts/ConstructSystem/FoodMakerController.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class FoodMakerController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float foodMax = 50f;
|
||||
|
||||
[SerializeField] private float foodRate = 1f;
|
||||
|
||||
private float food;
|
||||
|
||||
private TMP_Text foodIndicator;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
food = 0f;
|
||||
|
||||
foodIndicator = transform.Find("FoodIndicator").GetComponent<TMP_Text>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
food = Mathf.Clamp(food + foodRate * Time.deltaTime, 0f, foodMax);
|
||||
foodIndicator.SetText("Food:\n" + Mathf.FloorToInt(food));
|
||||
}
|
||||
|
||||
// called whenever the player collects the resources from this construct
|
||||
public float CollectAll()
|
||||
{
|
||||
var amount = food;
|
||||
food = 0f;
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void Disassemble()
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
11
Assets/Scripts/ConstructSystem/FoodMakerController.cs.meta
Normal file
11
Assets/Scripts/ConstructSystem/FoodMakerController.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1508925f2df548bdb47bdce29154c00
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user