敵の頭上にHPパネルを設置する











スライダーを変化させる
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class EnemyHPSlider : MonoBehaviour
{
private Slider slider;
private int eHP;
void Start()
{
// (ポイント)
// transform.root.gameObject・・・>Findを使わずに、一番上の階層にある親の情報を取得できる。
eHP = transform.root.gameObject.GetComponent<EnemyHealth>().enemyHP;
slider = GetComponent<Slider>();
slider.value = eHP;
slider.maxValue = eHP;
}
void Update()
{
eHP = transform.root.gameObject.GetComponent<EnemyHealth>().enemyHP;
slider.value = eHP;
}
}




正面に表示する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class EnemyHPSlider : MonoBehaviour {
private Slider slider;
private int eHP;
// ★プレーヤーの正面に表示
private GameObject enemyCanvas;
void Start () {
eHP = transform.root.gameObject.GetComponent<EnemyHealth>().enemyHP;
slider = GetComponent<Slider>();
slider.value = eHP;
slider.maxValue = eHP;
// ★プレーヤーの正面に表示
// transform.parent・・・>すぐ上の階層の親の情報を取得できる
enemyCanvas = transform.parent.gameObject;
}
void Update () {
eHP = transform.root.gameObject.GetComponent<EnemyHealth>().enemyHP;
slider.value = eHP;
// ★プレーヤーの正面に表示
enemyCanvas.transform.LookAt(GameObject.Find("FPSCamera").transform);
}
}

EscapeCombat
他のコースを見る










スライダーを変化させる
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class EnemyHPSlider : MonoBehaviour
{
private Slider slider;
private int eHP;
void Start()
{
// (ポイント)
// transform.root.gameObject・・・>Findを使わずに、一番上の階層にある親の情報を取得できる。
eHP = transform.root.gameObject.GetComponent<EnemyHealth>().enemyHP;
slider = GetComponent<Slider>();
slider.value = eHP;
slider.maxValue = eHP;
}
void Update()
{
eHP = transform.root.gameObject.GetComponent<EnemyHealth>().enemyHP;
slider.value = eHP;
}
}




正面に表示する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class EnemyHPSlider : MonoBehaviour {
private Slider slider;
private int eHP;
// ★プレーヤーの正面に表示
private GameObject enemyCanvas;
void Start () {
eHP = transform.root.gameObject.GetComponent<EnemyHealth>().enemyHP;
slider = GetComponent<Slider>();
slider.value = eHP;
slider.maxValue = eHP;
// ★プレーヤーの正面に表示
// transform.parent・・・>すぐ上の階層の親の情報を取得できる
enemyCanvas = transform.parent.gameObject;
}
void Update () {
eHP = transform.root.gameObject.GetComponent<EnemyHealth>().enemyHP;
slider.value = eHP;
// ★プレーヤーの正面に表示
enemyCanvas.transform.LookAt(GameObject.Find("FPSCamera").transform);
}
}

敵の頭上にHPパネルを設置する