Code : Tout sélectionner
Vector3 objPos = (Camera.)WorldToScreenPoint(this.transform.position);
GUI.DrawTexture(new Rect(objPos.x, objPos.y, hpBarLength, 10), HpBarTexture);
Je voudrais "simplement" mettre ma Barre de HP au dessus d'un objet dans ma scéne seulement elle est en GUI.DrawTexture et je ne sais pas si c'est possible.
Voila le code en question (que j'ai trouvé et très peu modifié (pour qu'il marche)sur internet)
Code : Tout sélectionner
using UnityEngine;
using System.Collections;
public class HpBar : MonoBehaviour {
public float curHp = 300f;
public float maxHp = 300f;
public Texture HpBarTexture;
private float hpBarLength;
private float percentOfHp;
void OnGUI () {
if (curHp > 0) {
GUI.DrawTexture(new Rect(10, 10, hpBarLength, 10), HpBarTexture);
}
}
void Update () {
percentOfHp = curHp/maxHp;
hpBarLength = percentOfHp*100;
if(Input.GetKeyDown("h")) {
curHp -= 10f;
}
}
}
Merci ^^' .