Вот что готово;
Немного осваивая ГУИ написал вот такой скрипт ;
using UnityEngine;
using System.Collections;
public class NameUnit : MonoBehaviour {
private RaycastHit hit;
public string UnitName;
public Color ColorText;
public int UnitHP;
public int HP=0;
public Color ColorHP;
public int UnitEnergy;
public int E=0;
public Color ColorEnergy;
private float distanceVector;
public Transform AlienUnit;
void Start () {
}
Vector3 TextPos;
void OnGUI()
{
TextPos = Camera.main.WorldToScreenPoint (transform.position);
if (Input.GetKey(KeyCode.Q))
{
GUI.Label (new Rect (TextPos.x, Screen.height - TextPos.y, 50, 50), UnitName);
GUI.color = Color.black + ColorText;
GUI.Label (new Rect (TextPos.x, Screen.height - TextPos.y - (20), 50, 50), "HP:" + UnitHP);
}
//Transform Unit;
distanceVector = Vector3.Distance (gameObject.transform.position , AlienUnit.position);
if (distanceVector <2)
{
if (Input.GetKeyDown (KeyCode.F1)) {
UnitHP -= 10;
}
if (Input.GetKeyDown (KeyCode.F2)) {
UnitEnergy -= 10;
}
//if (Input.GetKeyDown (KeyCode.F3)) {
// UnitHP += 10;
//}
//if (Input.GetKeyDown (KeyCode.F4)) {
// UnitEnergy += 10;
//}
}
//UnitHP
HP = UnitHP;
if (HP>99){HP=100;}
if (HP<1){gameObject.active= false;}
GUI.color = Color.black+ColorHP;
for (int i = 0; i <HP; i=i+1)
{
GUI.Label (new Rect ((TextPos.x+(i)-HP/2), Screen.height - TextPos.y - (35), 10, 10), "|");
}
//UnitEnergy
E = UnitEnergy;
if (E>99){E=100;}
if (E<1){E=0; UnitEnergy=0;}
GUI.color = Color.black+ColorEnergy;
for (int i = 0; i <E; i=i+1)
{
GUI.Label (new Rect ((TextPos.x+(i)-E/2), Screen.height - TextPos.y - (30), 10, 10), "|");
}
}
void Update ()
{
}
}
Появилось ХП и Энергия чтобы отнять нужно чтобы зеленый маркер находился рядом c юнитом. “F1” отнять ХП “F2” отнять Энергию.
“Q” подробности. Юнит исчезает если HP=0
Теперь надо обернуть всё в базовый класс ну ООП вобщем…
Немного разобрался с ГУИ.
На скриншоте с зажатой “Q” подробности.