Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour {
public int maxHealth = 100;
private int _curHealth = 100;
private float healthBarLength;
// Use this for initialization
void Start () {
healthBarLength = Screen.width / 2;
if (maxHealth<1) maxHealth = 1;
_curHealth = maxHealth;
}
// Update is called once per frame
void Update () {
AddjustCurrentHealth(_curHealth);
}
void OnGui () {
GUI.Box(new Rect(10,10,healthBarLength,20),_curHealth + "/" + maxHealth);
}
public void AddjustCurrentHealth(int adj){
_curHealth = adj;
if(_curHealth<0)_curHealth=0;
if(_curHealth<maxHealth)_curHealth = maxHealth;
healthBarLength =(Screen.width / 2) * (_curHealth / (float) maxHealth);
}
}
using System.Collections;
public class PlayerHealth : MonoBehaviour {
public int maxHealth = 100;
private int _curHealth = 100;
private float healthBarLength;
// Use this for initialization
void Start () {
healthBarLength = Screen.width / 2;
if (maxHealth<1) maxHealth = 1;
_curHealth = maxHealth;
}
// Update is called once per frame
void Update () {
AddjustCurrentHealth(_curHealth);
}
void OnGui () {
GUI.Box(new Rect(10,10,healthBarLength,20),_curHealth + "/" + maxHealth);
}
public void AddjustCurrentHealth(int adj){
_curHealth = adj;
if(_curHealth<0)_curHealth=0;
if(_curHealth<maxHealth)_curHealth = maxHealth;
healthBarLength =(Screen.width / 2) * (_curHealth / (float) maxHealth);
}
}
Что посоветуете?