Unity Script


SUBMITTED BY: apal2

DATE: July 17, 2017, 1:29 a.m.

FORMAT: C#

SIZE: 1.8 kB

HITS: 241

  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. public class SignesVitaux : MonoBehaviour
  5. {
  6. public Slider sliderVie;
  7. public int maxVie;
  8. public float perteVie;
  9. public Slider sliderFaim;
  10. public int maxFaim;
  11. public float perteFaim;
  12. public Slider sliderSoif;
  13. public int maxSoif;
  14. public float perteSoif;
  15. void Start()
  16. {
  17. sliderVie.maxValue = maxVie;
  18. sliderVie.value = maxVie;
  19. sliderFaim.maxValue = maxFaim;
  20. sliderFaim.value = maxFaim;
  21. sliderSoif.maxValue = maxSoif;
  22. sliderSoif.value = maxSoif;
  23. }
  24. void Update()
  25. {
  26. if (sliderFaim.value <= 0 && (sliderSoif.value <= 0))
  27. {
  28. sliderVie.value -= Time.deltaTime / perteVie * 2;
  29. }
  30. else if (sliderSoif.value <= 0 || sliderFaim.value <= 0)
  31. {
  32. sliderVie.value -= Time.deltaTime / perteVie;
  33. }
  34. if (sliderVie.value <= 0)
  35. {
  36. mortJoueur();
  37. }
  38. if (sliderFaim.value >= 0)
  39. {
  40. sliderFaim.value -= Time.deltaTime / perteFaim;
  41. }
  42. else if (sliderFaim.value <= 0)
  43. {
  44. sliderFaim.value = 0;
  45. }
  46. else if (sliderFaim.value >= maxFaim)
  47. {
  48. sliderFaim.value = maxFaim;
  49. }
  50. if (sliderSoif.value >= 0)
  51. {
  52. sliderSoif.value -= Time.deltaTime / perteSoif;
  53. }
  54. else if (sliderSoif.value <= 0)
  55. {
  56. sliderSoif.value = 0;
  57. }
  58. else if (sliderSoif.value >= maxSoif)
  59. {
  60. sliderSoif.value = maxSoif;
  61. }
  62. }
  63. void mortJoueur()
  64. {
  65. }
  66. }

comments powered by Disqus