using UnityEngine;
using System.Collections;
public class StatyPostaci : MonoBehaviour {
private float MaxZycie = 100;
public float AktualneZycie = 100;
private float MaxNawodnienie = 100;
public float AktualneNawodnienie = 100;
private float MaxGlod = 100;
public float AktualnyGlod = 100;
public Texture2D ZycieTextura;
public Texture2D NawodnienieTextura;
public Texture2D GlodTextura;
private float barWidth;
private float barHeight;
public float timerGlodu = 40;
public float timerNawodnienia = 10;
public float timerZycia = 5;
void Awake() {
barHeight = Screen.height * 0.02f;
barWidth = barHeight * 10.0f;
}
void OnGUI() {
GUI.DrawTexture (new Rect (Screen.width - barWidth - 10,
Screen.height - barHeight - 10,
AktualneZycie * barWidth / MaxZycie,
barHeight), ZycieTextura);
GUI.DrawTexture (new Rect (Screen.width - barWidth - 10,
Screen.height - barHeight * 2 - 10,
AktualneNawodnienie * barWidth / MaxNawodnienie,
barHeight), NawodnienieTextura);
GUI.DrawTexture (new Rect (Screen.width - barWidth - 10,
Screen.height - barHeight * 3 - 10,
AktualnyGlod * barWidth / MaxGlod,
barHeight), GlodTextura);
}
void Start () {
}
void Update () {
if (AktualneZycie <= 0) {
AktualneZycie = 0;
}
if (AktualnyGlod <= 0) {
AktualnyGlod = 0;
}
if (AktualneNawodnienie <= 0) {
AktualneNawodnienie = 0;
}
if (AktualneNawodnienie >=100) {
AktualneNawodnienie = 100;
}
if (AktualneZycie >=100) {
AktualneZycie = 100;
}
if (AktualnyGlod >=100) {
AktualnyGlod = 100;
}
timerGlodu -= Time.deltaTime;
timerNawodnienia -= Time.deltaTime;
if (timerGlodu <= 0) {
AktualnyGlod -= 20;
timerGlodu = 40;
}
if (timerNawodnienia <= 0) {
AktualneNawodnienie -= 5;
timerNawodnienia = 10;
}
if (AktualnyGlod <= 1) {
timerZycia -= Time.deltaTime;
if(timerZycia <=0){
AktualneZycie -= 5;
timerZycia = 5;
}
}
}
}
**Line 5**
↧