Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerState : MonoBehaviour
- {
- public static PlayerState Instance { get; set; }
- // --- Player Health --- \\
- public float currentHealth;
- public float maxHealth;
- // --- Player Calories --- \\
- public float currentCalories;
- public float maxCalories;
- float distanceTraveled = 0;
- Vector3 lastPosition;
- public GameObject playerBody;
- // --- Player Hydration --- \\
- public float currentHydrationPercent;
- public float maxHydrationPercent;
- public bool isHydrationActive;
- private void Awake()
- {
- if (Instance != null && Instance != this)
- {
- Destroy(gameObject);
- }
- else
- {
- Instance = this;
- }
- }
- private void Start()
- {
- currentHealth = maxHealth;
- currentCalories = maxCalories +10;
- currentHydrationPercent = maxHydrationPercent +1;
- StartCoroutine(decreaseHydration());
- }
- IEnumerator decreaseHydration()
- {
- while (true)
- {
- currentHydrationPercent -= 1;
- yield return new WaitForSeconds(10);
- }
- }
- // Update is called once per frame
- void Update()
- {
- // Calories Bar
- distanceTraveled += Vector3.Distance(playerBody.transform.position, lastPosition);
- lastPosition = playerBody.transform.position;
- if (distanceTraveled >=5) //I changed the amount from the video
- {
- distanceTraveled = 0;
- currentCalories -= 10; //I changed the amount from the video (I also added 10 in the start method to keep the calories correct at the start)
- }
- // Testing the health bar
- if (Input.GetKeyDown(KeyCode.N))
- {
- currentHealth -= 10;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement