ゲーム画面では、表示が崩れるため
PlayerController.csのvoid Update () {に
//現在のヒットポイントをUiCanvasに送る
GameObject.Find ("UiCanvas").GetComponent
().playerHp = MyHitPoint;
GameObject.Find ("UiCanvas").GetComponent ().playerAp = MyAttackPoint;
GameObject.Find ("UiCanvas").GetComponent ().playerDp = MyDiffencePoint;
に変更
playerPra.csのtextを
text = "Name" +"\n"+
"HitPoint : " + gameObject.GetComponentInParent ().playerHp.ToString () +"\n"+
"AttackPoint :"+ gameObject.GetComponentInParent ().playerAp.ToString ()+"\n"+
"DiffencePoint :"+ gameObject.GetComponentInParent ().playerDp.ToString ();
そうすると

同様に
EnemyPraオブジェクトにenemyPra.csを作り
以下のようにする
using UnityEngine;
using UnityEngine.UI;//UI関係はここを入れる
using System.Collections;
public class enemyPra : MonoBehaviour {
public GUIStyle labelStyle;
private string text;
// Use this for initialization
void Start () {
//UI.text変更
Text target = null;
target = gameObject.GetComponent();
target.text = "";
//UI.text変更
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
//そのラベルの大きさを決め
//細かい設定は、public GUIStyle labelStyle;を付けて確認するといい
labelStyle = new GUIStyle ();
labelStyle.fontSize = 14;
//位置を決める
labelStyle.alignment = TextAnchor.UpperLeft;
//ラベルの色を決める
GUIStyleState labelStyleState = new GUIStyleState();
labelStyleState.textColor = Color.black;
//反映させる
labelStyle.normal = labelStyleState;
//text = "ラベルの\n文字";
text = "Name" +"\n"+
"HitPoint : " + gameObject.GetComponentInParent ().EnemyHp.ToString () +"\n"+
"AttackPoint :"+ gameObject.GetComponentInParent ().EnemyAp.ToString ()+"\n"+
"DiffencePoint :"+ gameObject.GetComponentInParent ().EnemyDp.ToString ();
//.ToString();S
//ラベルを表示させる
GUI.Label (new Rect(600,20,100,100),text,labelStyle);
}
}
EnemyMove.csのvoid Update(){
に
//現在のヒットポイントをUiCanvasに送る
GameObject.Find ("UiCanvas").GetComponent ().EnemyHp = MyHitPoint;
GameObject.Find ("UiCanvas").GetComponent ().EnemyAp = MyAttackPoint;
GameObject.Find ("UiCanvas").GetComponent ().EnemyDp = MyDiffencePoint;
を追加
- 関連記事
-
YouTubeで動画を定期的に出しています。ご視聴いただけると嬉しいです。
Reon Labo
- 2016/12/10(土) 18:00:00|
- Unity
-
| トラックバック:0
-
| コメント:0