/* * Script par Tanguy Gimenez * */ using UnityEngine; using System; using System.Timers; public class PlayerNature : MonoBehaviour { // l'instance de PlayerNature (pour un singleton) public static PlayerNature instance; // Nombre max de points de nature que le joueur peut avoir (objectif à atteindre) public int maxNature = 200; // Quantité de points actuel public int currentNature; // Jauge de points de nature public Bar natureBar; // durée en ms ou a chaque fois, le joueur perd un certain nombre de pv public int duree = 1000; // dommage pris tout les x ms si t'es dans la ville public int TimeDamage; private float nextActionTime = 0.0f; public float period = 0.1f; void Start() { // initialisation des points de nature this.natureBar.SetMaxNature(this.maxNature); this.natureBar.SetValue(this.currentNature); } void Update() { ////toutes les x secondes => on perd un certain nombre de secondes //if (Time.time > nextActionTime) //{ // nextActionTime += period; // this.LooseNature(this.TimeDamage); //} } // Perd un certain nombre de points de nature public void LooseNature(int damage) { this.currentNature -= damage; if(this.currentNature < 0) this.currentNature = 0; this.natureBar.SetValue(this.currentNature); } // Gagne un certain nombre de points de nature public void WinNature(int bonus) { this.currentNature += bonus; if (this.currentNature >= 100) this.currentNature = 100; this.natureBar.SetValue(this.currentNature); } // Singleton private void Awake() { if (instance != null) { Debug.LogWarning("Il y a + d'une instance de PlayerNature"); return; } instance = this; } }