HitPoint表示 1
HitPoint表示
LabelPfbという名前のオブジェクトを作る
Hierarchy>右クリック>CreateEmpty
prefab化する
HierarchyにあるLabelPfbを消す
Project>Assets>Prefabs>labelPfb
AddComponent>Mesh>MeshRenderer
AddComponent>Mesh>TextMesh
TextMeshのFontに、使用するFontを追加
に、labelDisp.csを追加する

Hirarchy>PlayerにPlayerGui.cs
Hierarchy>EnemyにenemyGui.cs
を作る
-----labelDisp.cs-----------
using UnityEngine;
using System.Collections;
public class labelDisp : MonoBehaviour {
GameObject player;
public int myHp;
// Use this for initialization
void Start () {
player = GameObject.Find("Player");
//親オブジェクトを確認
Vector3 parentsPosX = gameObject.transform.parent.position;
Debug.Log ("親ポジション"+parentsPosX);
if (gameObject.transform.parent.tag == "Player") {
myHp = gameObject.GetComponentInParent
().MyHitPoint;
}
if (gameObject.transform.parent.tag == "Enemy") {
myHp = gameObject.GetComponentInParent().MyHitPoint;
}
}
// Update is called once per frame
void Update () {
if (gameObject.transform.parent.tag == "Player") {
myHp = gameObject.GetComponentInParent().MyHitPoint;
}
if (gameObject.transform.parent.tag == "Enemy") {
myHp = gameObject.GetComponentInParent().MyHitPoint;
//カメラの向きと合わせると、常に正面を向く
transform.rotation =player.transform.rotation;
}
GetComponent ().text = myHp.ToString();
}
}
-----labelDisp.cs-----------
- 関連記事
-
YouTubeで動画を定期的に出しています。ご視聴いただけると嬉しいです。
Reon Labo
- 2016/11/24(木) 18:00:00|
- Unity
-
| トラックバック:0
-
| コメント:0