こんな風に出せるようにしたいが
Playerの状態を読み込むのは、問題ないが
Enemyの方は、攻撃している時に表示するようにしたい
PlayerPraからScriptを作ってみる
簡単なGUIの説明
GUIシステムを表示させるための関数
文字とかボタンとかを表示させるスクリプトを書いていく
void OnGUI(){
}
そのラベルの大きさを決め
//細かい設定は、public GUIStyle labelStyle;を付けて確認するといい
GUIStyle labelStyle = new GUIStyle ();
labelStyle.fontSize = 32;
位置を決める
labelStyle.alignment = TextAnchor.MiddleCenter;
※
ラベルの色を決める
GUIStyleState labelStyleState = new GUIStyleState();
labelStyleState.textColor = Color.white;
反映させる
labelStyle.normal = labelStyleState;
ラベルを表示させる
GUI.Label (new Rect(x,y,width,height),”ラベルの文字”,labelStyle);
改行させる時は \n 出し方は alt+\
ボタンを表示
if(GUI.Button(new Rect(x,y,width,height),”ボタンの名前”)){
}
・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・
PlayerController.csのvoid Update () {に
//現在のヒットポイントをCanvasに送る
GameObject.Find ("Canvas").GetComponent
().playerHp = MyHitPoint;
を追加
playePraオブジェクトにplayerPra.csを作り以下のようにする
using UnityEngine;
using UnityEngine.UI;//UI関係はここを入れる
using System.Collections;
public class playerPra : 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.white;
//反映させる
labelStyle.normal = labelStyleState;
//text = "ラベルの\n文字";
text = gameObject.GetComponentInParent ().playerHp.ToString ();
//.ToString();
//ラベルを表示させる
GUI.Label (new Rect(20,20,100,100),text,labelStyle);
}
}
UiCanvax(Canbas)に、parameter.csを作り
中身を以下のようにする
---parameter.cs------------------
using UnityEngine;
using System.Collections;
public class parameter : MonoBehaviour {
//player設定
public int playerHp;
public int playerAp;
public int playerDp;
public int playerMp;
//Enemy設定
public int EnemyHp;
public int EnemyAp;
public int EnemyDp;
public int EnemyMp;
GameObject NowEnemy;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
---parameter.cs------------------
とすると

- 関連記事
-
YouTubeで動画を定期的に出しています。ご視聴いただけると嬉しいです。
Reon Labo
- 2016/12/06(火) 18:00:00|
- Unity
-
| トラックバック:0
-
| コメント:0