Hey i converted from java to c# i want to use for my enemy and anything i change keeps giving me error if any can help please thank you.
using UnityEngine;
using System.Collections;
public class AIHealth : MonoBehaviour {
public Transform HPtarget;
GameObject HPfabbie;
GameObject HPGUI;
FIXME_VAR_TYPE healthGUIWidth= 0.0f;
void Start (){
HPGUI = Instantiate(HPfabbie,Vector3(0.5f,0.5f,0),Quaternion.identity)as GameObject;
healthGUIWidth = HPGUI.guiTexture.pixelInset.width;
}
void Update (){
FIXME_VAR_TYPE mainCamera= FindCamera();
FIXME_VAR_TYPE p= mainCamera.WorldToViewportPoint(HPtarget.position+Vector3.up*1.5f);
FIXME_VAR_TYPE healthFraction= 0.5f;
HPGUI.guiTexture.pixelInset.xMax = HPGUI.guiTexture.pixelInset.xMin + healthGUIWidth * healthFraction;
HPGUI.transform.position = p;
}
void FindCamera (){
if (camera)
return camera;
else
return Camera.main;
}
}
i was using this other script but the healthbar keeps showing behind other objects
using UnityEngine;
using System.Collections;
public class AIHealth : MonoBehaviour {
public float hp=100;
public float healthBarWidth;
public GameObject AIhealthBar;
public GameObject myHb;
void Start (){
healthBarWidth=20f;
myHb = Instantiate (AIhealthBar, transform.position, transform.rotation) as GameObject;
}
void Update (){
// Health bar
myHb.transform.position = Camera.main.WorldToViewportPoint(transform.position);
myHb.transform.localScale = Vector3.zero;
healthBarWidth = -hp;
if( hp > 100){
hp = 100;
}
myHb.guiTexture.pixelInset = new Rect(10,20,healthBarWidth, 10);
}
}