The fucking 3rd time i had to upload this project to git
This commit is contained in:
28
Assets/Scripts/Player/Information/PlayerDialogue.cs
Normal file
28
Assets/Scripts/Player/Information/PlayerDialogue.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Player.Information
|
||||
{
|
||||
public class PlayerDialogue : MonoBehaviour
|
||||
{
|
||||
public GameObject dialogueMaster;
|
||||
|
||||
private GameObject chatHolder;
|
||||
private GameObject chatPrompt;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
chatHolder = dialogueMaster.transform.Find("Chat Holder").gameObject;
|
||||
chatPrompt = dialogueMaster.transform.Find("Chat Prompt").gameObject;
|
||||
chatHolder.SetActive(false);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.LeftAlt))
|
||||
{
|
||||
chatHolder.SetActive(!chatHolder.activeSelf);
|
||||
chatPrompt.SetActive(!chatPrompt.activeSelf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/Information/PlayerDialogue.cs.meta
Normal file
11
Assets/Scripts/Player/Information/PlayerDialogue.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc09d3a52bf3249bca6ecf5691ea62e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
154
Assets/Scripts/Player/Information/PlayerStats.cs
Normal file
154
Assets/Scripts/Player/Information/PlayerStats.cs
Normal file
@ -0,0 +1,154 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Player.Movement;
|
||||
|
||||
namespace Player.Information
|
||||
{
|
||||
public class PlayerStats : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float maxHealth = 100;
|
||||
|
||||
[SerializeField] private float healthDepleteRate = 1;
|
||||
|
||||
[SerializeField] private float maxHunger = 20f;
|
||||
|
||||
[SerializeField] private float maxHydration = 10f;
|
||||
|
||||
[SerializeField] private int nanites = 10;
|
||||
|
||||
[SerializeField] private Transform spawnpoint;
|
||||
|
||||
[SerializeField] public bool jetpackEnabled;
|
||||
|
||||
[SerializeField] public bool inputEnabled = true;
|
||||
|
||||
public bool grappleEnabled;
|
||||
private float health;
|
||||
private Image healthContent;
|
||||
|
||||
private float hunger;
|
||||
private Image hungerContent;
|
||||
|
||||
private float hydration;
|
||||
private Image hydrationContent;
|
||||
private TMP_Text naniteContent;
|
||||
|
||||
private PlayerPhysics playerPhysics;
|
||||
|
||||
private GameObject statUI;
|
||||
|
||||
private Image thrustContent;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
health = maxHealth;
|
||||
hunger = maxHunger;
|
||||
hydration = maxHydration;
|
||||
|
||||
statUI = GameObject.Find("Survival Stats");
|
||||
healthContent = statUI.transform.Find("Health Bar/Health Value").gameObject.GetComponent<Image>();
|
||||
hungerContent = statUI.transform.Find("Hunger Bar/Hunger Value").gameObject.GetComponent<Image>();
|
||||
hydrationContent = statUI.transform.Find("Hydration Bar/Hydration Value").gameObject.GetComponent<Image>();
|
||||
naniteContent = statUI.transform.Find("Nanite Bar").gameObject.GetComponent<TMP_Text>();
|
||||
|
||||
thrustContent = statUI.transform.Find("Thrust Bar/Thrust Value").gameObject.GetComponent<Image>();
|
||||
|
||||
SetNanites(nanites);
|
||||
|
||||
playerPhysics = gameObject.GetComponent<PlayerPhysics>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
TickStats();
|
||||
}
|
||||
|
||||
//called each frame to update stat values
|
||||
public void TickStats()
|
||||
{
|
||||
TickHunger();
|
||||
TickHydration();
|
||||
if (hunger == 0f || hydration == 0f) ChangeHealth(-healthDepleteRate * Time.deltaTime);
|
||||
if (health == 0)
|
||||
{
|
||||
Debug.Log("player died");
|
||||
Respawn();
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeStat(ref float stat, float maxStat, float change, ref Image statContent)
|
||||
{
|
||||
stat = Mathf.Clamp(stat + change, 0f, maxStat);
|
||||
statContent.fillAmount = Mathf.Clamp(stat / maxStat, 0f, 1f);
|
||||
}
|
||||
|
||||
public void TickHunger()
|
||||
{
|
||||
ChangeHunger(-Time.deltaTime);
|
||||
}
|
||||
|
||||
public void TickHydration()
|
||||
{
|
||||
ChangeHydration(-Time.deltaTime);
|
||||
}
|
||||
|
||||
public void ChangeHealth(float change)
|
||||
{
|
||||
ChangeStat(ref health, maxHealth, change, ref healthContent);
|
||||
}
|
||||
|
||||
public void ChangeHunger(float change)
|
||||
{
|
||||
ChangeStat(ref hunger, maxHunger, change, ref hungerContent);
|
||||
}
|
||||
|
||||
public void ChangeHydration(float change)
|
||||
{
|
||||
ChangeStat(ref hydration, maxHydration, change, ref hydrationContent);
|
||||
}
|
||||
|
||||
public void ConsumeResource(float change, string name)
|
||||
{
|
||||
if (name == "Food")
|
||||
ChangeHunger(change);
|
||||
else if (name == "Water")
|
||||
ChangeHydration(change);
|
||||
else if (name == "Health") ChangeHealth(change);
|
||||
}
|
||||
|
||||
public int GetNanites()
|
||||
{
|
||||
return nanites;
|
||||
}
|
||||
|
||||
public void SetNanites(int s)
|
||||
{
|
||||
nanites = s;
|
||||
naniteContent.SetText(nanites.ToString());
|
||||
}
|
||||
|
||||
public void ChangeNanites(int c)
|
||||
{
|
||||
SetNanites(nanites + c);
|
||||
}
|
||||
|
||||
public void Respawn()
|
||||
{
|
||||
// Note, this respawn script will have to be more advanced in later versions.
|
||||
ChangeHealth(maxHealth);
|
||||
ChangeHunger(maxHunger);
|
||||
ChangeHydration(maxHydration);
|
||||
transform.position = spawnpoint.position;
|
||||
transform.rotation = spawnpoint.rotation;
|
||||
playerPhysics.Reset();
|
||||
}
|
||||
|
||||
public void SetThrust(float amount)
|
||||
{
|
||||
thrustContent.fillAmount = amount;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/Information/PlayerStats.cs.meta
Normal file
11
Assets/Scripts/Player/Information/PlayerStats.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0d818a45884a4068a5ac6a6cbdb184e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user