敵の作成⑤(オーバーライド:敵のHPスライダーの作成)

















オーバーライド(HPスライダー)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加
using UnityEngine.UI;
public class EnemyA : EnemyBase
{
// ★追加
public Slider HPSlider;
void Start()
{
HP = 5;
// ★追加
HPSlider.maxValue = HP;
HPSlider.value = HP;
}
// ★追加(オーバーライド)
// overrideキーワードを忘れないこと
public override void TakeDamage(int missilePower)
{
HP -= missilePower;
HPSlider.value = HP;
if (HP < 1)
{
Destroy(gameObject);
}
}
}



【2021版】Danmaku(基礎/全55回)
他のコースを見る
















オーバーライド(HPスライダー)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加
using UnityEngine.UI;
public class EnemyA : EnemyBase
{
// ★追加
public Slider HPSlider;
void Start()
{
HP = 5;
// ★追加
HPSlider.maxValue = HP;
HPSlider.value = HP;
}
// ★追加(オーバーライド)
// overrideキーワードを忘れないこと
public override void TakeDamage(int missilePower)
{
HP -= missilePower;
HPSlider.value = HP;
if (HP < 1)
{
Destroy(gameObject);
}
}
}



敵の作成⑤(オーバーライド:敵のHPスライダーの作成)