mirror of
https://github.com/DerTyp7/example-top-down-unity.git
synced 2025-10-29 12:32:09 +01:00
base vitality
This commit is contained in:
@@ -513,7 +513,7 @@ MonoBehaviour:
|
||||
m_OnCullStateChanged:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_text: interaction text
|
||||
m_text:
|
||||
m_isRightToLeft: 0
|
||||
m_fontAsset: {fileID: 11400000, guid: 4311e961a11edf545ba020d711a5b017, type: 2}
|
||||
m_sharedMaterial: {fileID: -5352834521635484852, guid: 4311e961a11edf545ba020d711a5b017, type: 2}
|
||||
@@ -810,7 +810,6 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
partOfDay: 0
|
||||
intervalTime: 1
|
||||
minutesPerInterval: 1
|
||||
--- !u!4 &273326178
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -911,13 +910,15 @@ GameObject:
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 310196954}
|
||||
- component: {fileID: 310196953}
|
||||
- component: {fileID: 310196952}
|
||||
- component: {fileID: 310196951}
|
||||
- component: {fileID: 310196955}
|
||||
- component: {fileID: 310196956}
|
||||
- component: {fileID: 310196957}
|
||||
- component: {fileID: 310196958}
|
||||
- component: {fileID: 310196959}
|
||||
- component: {fileID: 310196953}
|
||||
- component: {fileID: 310196956}
|
||||
- component: {fileID: 310196951}
|
||||
- component: {fileID: 310196955}
|
||||
- component: {fileID: 310196960}
|
||||
m_Layer: 3
|
||||
m_Name: Player
|
||||
m_TagString: Player
|
||||
@@ -1090,6 +1091,36 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
interactionText: {fileID: 87507994}
|
||||
interactionProgressImg: {fileID: 138750307}
|
||||
--- !u!114 &310196959
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 310196950}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 259b4dba2ac00aa4983a6562c5f4eed5, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
health: 1
|
||||
food: 1
|
||||
drink: 1
|
||||
healthModifier: 15
|
||||
foodModifier: 0.4
|
||||
drinkModifier: 0.6
|
||||
--- !u!114 &310196960
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 310196950}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 5ee4c18f008d122488cbb74c779ef5c4, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &360525550
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
8
Assets/Scripts/Player.meta
Normal file
8
Assets/Scripts/Player.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 415ae7da5bed43345b965569c9070e15
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
11
Assets/Scripts/Player/Player.cs
Normal file
11
Assets/Scripts/Player/Player.cs
Normal 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!!! -----");
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Player/Player.cs.meta
Normal file
11
Assets/Scripts/Player/Player.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ee4c18f008d122488cbb74c779ef5c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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()
|
||||
{
|
||||
timer -= Time.deltaTime;
|
||||
|
||||
if (timer <= 0)
|
||||
{
|
||||
dateTime = dateTime.AddMinutes(minutesPerInterval);
|
||||
CheckPartsOfDay();
|
||||
OnTimeInterval?.Invoke();
|
||||
timer = intervalTime;
|
||||
}
|
||||
}
|
||||
|
||||
void CheckPartsOfDay()
|
||||
|
||||
61
Assets/Scripts/Vitality.cs
Normal file
61
Assets/Scripts/Vitality.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Vitality.cs.meta
Normal file
11
Assets/Scripts/Vitality.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 259b4dba2ac00aa4983a6562c5f4eed5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user