Can any one help me with NPC GUI… like health bar and Question answer bar top of NPC characters … ?!
I wrote this one a short while back, it uses a Raycast to check what enemy has been targeted and accesses a script that governs their health.
private var isActivelyWorking : boolean = true;//...
var currentTarget : GameObject;//The enemy itself
var targetsHP : EnemyHP;//Script for Enemy Health
var EHP01 : Texture2D;//HP = 100%
var EHP02 : Texture2D;//HP = 80%
var EHP03 : Texture2D;//HP = 60%
var EHP04 : Texture2D;//HP = 40%
var EHP05 : Texture2D;//HP = 20%
var EHP06 : Texture2D;//HP = 0%
function Start () {
guiTexture.texture = EHP01;
}
function Update () {
if (isActivelyWorking) {
var ray: Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit: RaycastHit;
if (Physics.Raycast(ray, hit)) {
if (hit.distance <= 24.0) {
if (hit.collider.tag == "Enemy") {
guiTexture.color.a = (0.5);
currentTarget = hit.collider.gameObject;
targetsHP = currentTarget.gameObject.GetComponent(EnemyHP);
if (targetsHP.baseEnemyHP > targetsHP.maxEnemyHP / 6 * 6){
guiTexture.texture = EHP01;
}
if (targetsHP.baseEnemyHP > targetsHP.maxEnemyHP / 6 * 4 targetsHP.baseEnemyHP < targetsHP.maxEnemyHP / 6 * 5){
guiTexture.texture = EHP02;
}
if (targetsHP.baseEnemyHP > targetsHP.maxEnemyHP / 6 * 3 targetsHP.baseEnemyHP < targetsHP.maxEnemyHP / 6 * 4){
guiTexture.texture = EHP03;
}
if (targetsHP.baseEnemyHP > targetsHP.maxEnemyHP / 6 * 2 targetsHP.baseEnemyHP < targetsHP.maxEnemyHP / 6 * 3){
guiTexture.texture = EHP04;
}
if (targetsHP.baseEnemyHP > targetsHP.maxEnemyHP / 6 * 1 targetsHP.baseEnemyHP < targetsHP.maxEnemyHP / 6 * 2){
guiTexture.texture = EHP05;
}
if (targetsHP.baseEnemyHP < targetsHP.maxEnemyHP / 6 * 1){
guiTexture.texture = EHP06;
}
}
if (hit.collider.tag != "Enemy") {
guiTexture.color.a = (0.0);
}
}
}
if (hit.distance >= 24.0) {
guiTexture.color.a = (0.0);
}
}
}
It’s intended to work sort of like the enemy health GUI in Assassins Creed 2, but in more of a FPS style, it might not be exactly what you’re looking for but you could probably work ObjectLabel into it somewhere so that the texture appears above the target.
Sorry if this isn’t a whole lot of help.
tnx, i try it when i rich to section…