|
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
public class PlayerState : MonoBehaviour |
|
{ |
|
public static PlayerState Instance { get; set; } |
|
public float currentHealth; |
|
public float maxHealth; |
|
public float currentCalories; |
|
public float maxCalories; |
|
public float currentHydration; |
|
public float maxHydration; |
|
|
|
float distanceTraveled = 0; |
|
Vector3 lastPosition; |
|
|
|
public GameObject playerBody; |
|
|
|
public bool isHydrationActive = true; |
|
|
|
private void Awake() |
|
{ |
|
if (Instance != null && Instance != this) |
|
{ |
|
DestroyObject(gameObject); |
|
} |
|
else |
|
{ |
|
Instance = this; |
|
} |
|
|
|
} |
|
|
|
|
|
void Start() |
|
{ |
|
currentHealth = maxHealth; |
|
currentCalories = maxCalories; |
|
currentHydration = maxHydration; |
|
|
|
StartCoroutine(decreaseHydration()); |
|
} |
|
|
|
IEnumerator decreaseHydration() |
|
{ |
|
while (isHydrationActive) |
|
{ |
|
currentHydration--; |
|
yield return new WaitForSeconds(20); |
|
} |
|
|
|
} |
|
|
|
|
|
void Update() |
|
{ |
|
distanceTraveled += Vector3.Distance(playerBody.transform.position, lastPosition); |
|
lastPosition = playerBody.transform.position; |
|
|
|
if (distanceTraveled >= 5) |
|
{ |
|
distanceTraveled = 0; |
|
currentCalories--; |
|
} |
|
} |
|
|
|
public void setCalories(float newCalories) |
|
{ |
|
currentCalories = newCalories; |
|
} |
|
|
|
internal void setHydration(float newHydration) |
|
{ |
|
currentHydration = newHydration; |
|
} |
|
|
|
internal void setHealth(float newHealth) |
|
{ |
|
currentHealth = newHealth; |
|
} |
|
} |
|
|