base vitality

This commit is contained in:
j.mei7
2022-02-19 16:48:48 +01:00
parent 97143a480f
commit 4d588c54ed
14 changed files with 587 additions and 565 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 415ae7da5bed43345b965569c9070e15
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public void Die()
{
Debug.Log("----- PLAYER DIED!!! -----");
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5ee4c18f008d122488cbb74c779ef5c4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -4,6 +4,7 @@ using UnityEngine;
public class TimeManager : MonoBehaviour
{
public static Action OnTimeInterval;
public enum PartOfDay
{
MORNING,
@@ -17,24 +18,33 @@ public class TimeManager : MonoBehaviour
[SerializeField]
float intervalTime = 1.0f; // 1.0f -> 1 real second is 1 ingame minute
[SerializeField]
int minutesPerInterval = 1;
DateTime dateTime = new DateTime(1, 1, 1, 23, 0, 0);
DateTime dateTime = new DateTime(1, 1, 1, 0, 0, 0);
float timer;
public DateTime GetDateTime() => dateTime;
public string GetTime() => dateTime.ToString("hh:mm tt");
public string GetDate() => dateTime.ToString("dd/mm/yyyy");
public float GetintervalTime() => intervalTime;
void Start()
{
InvokeRepeating("TimeUp", intervalTime, intervalTime);
timer = intervalTime;
}
void TimeUp()
void Update()
{
dateTime = dateTime.AddMinutes(minutesPerInterval);
CheckPartsOfDay();
timer -= Time.deltaTime;
if (timer <= 0)
{
dateTime = dateTime.AddMinutes(minutesPerInterval);
CheckPartsOfDay();
OnTimeInterval?.Invoke();
timer = intervalTime;
}
}
void CheckPartsOfDay()

View File

@@ -0,0 +1,61 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Vitality : MonoBehaviour
{
TimeManager timeManager;
Player player;
[Header("Vitality")]
[Range(0f, 1f)]
[SerializeField]
float health = 1f;
[Range(0f, 1f)]
[SerializeField]
float food = 1f;
[Range(0f, 1f)]
[SerializeField]
float drink = 1f;
[Header("Vitality Modifier Per Interval")]
[Range(0f, 50f)]
[SerializeField]
float healthModifier = 15f;
[Range(0f, 5f)]
[SerializeField]
float foodModifier = 0.4f;
[Range(0f, 5f)]
[SerializeField]
float drinkModifier = 0.6f;
private void Start()
{
timeManager = GameObject.Find("GameManager").GetComponent<TimeManager>();
TimeManager.OnTimeInterval += VitalityInterval;
player = gameObject.GetComponent<Player>();
}
void VitalityInterval()
{
food -= foodModifier / 1000;
drink -= drinkModifier / 1000;
if(food <= 0f || drink <= 0f)
{
health -= healthModifier / 1000;
}
if(health <= 0f)
{
player.Die();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 259b4dba2ac00aa4983a6562c5f4eed5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: