Skip to content
Snippets Groups Projects
PlayerNature.cs 1.93 KiB
Newer Older
GIMENEZ TANGUY's avatar
GIMENEZ TANGUY committed
/*
 *      Script par Tanguy Gimenez      
 *
 */

using UnityEngine;
using System;
using System.Timers;
GIMENEZ TANGUY's avatar
GIMENEZ TANGUY committed

public class PlayerNature : MonoBehaviour
GIMENEZ TANGUY's avatar
GIMENEZ TANGUY committed
{

    // 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
GIMENEZ TANGUY's avatar
GIMENEZ TANGUY committed
    public int currentNature;

    // Jauge de points de nature
GIMENEZ TANGUY's avatar
GIMENEZ TANGUY committed
    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;
GIMENEZ TANGUY's avatar
GIMENEZ TANGUY committed
    void Start()
    {
        // initialisation des points de nature
GIMENEZ TANGUY's avatar
GIMENEZ TANGUY committed
        this.natureBar.SetMaxNature(this.maxNature);
        this.natureBar.SetValue(this.currentNature);


GIMENEZ TANGUY's avatar
GIMENEZ TANGUY committed
    }
    void Update()
    {
        ////toutes les x secondes => on perd un certain nombre de secondes
        //if (Time.time > nextActionTime)
        //{
        //    nextActionTime += period;
        //    this.LooseNature(this.TimeDamage);
        //}
GIMENEZ TANGUY's avatar
GIMENEZ TANGUY committed
    }
    // Perd un certain nombre de points de nature
GIMENEZ TANGUY's avatar
GIMENEZ TANGUY committed
    public void LooseNature(int damage)
    {
        this.currentNature -= damage;
GIMENEZ TANGUY's avatar
GIMENEZ TANGUY committed

        if(this.currentNature < 0)
            this.currentNature = 0;

GIMENEZ TANGUY's avatar
GIMENEZ TANGUY committed
        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;
    }
GIMENEZ TANGUY's avatar
GIMENEZ TANGUY committed
}