アイテムの作成④(攻撃力アップ)











攻撃力アップ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PowerUPItem : Item // 「MonoBehaviour」を「Item」に変更する(これで「Itemクラスを承継」することができます。)
{
private GameObject fireMissile_B;
private GameObject fireMissile_C;
private void Start()
{
fireMissile_B = GameObject.Find("FireMissileB");
fireMissile_C = GameObject.Find("FireMissileC");
}
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Missile")
{
// (重要ポイント)ItemクラスのItemBaseメソッドを呼び出す。
base.ItemBase(other.gameObject);
if (fireMissile_B && fireMissile_C)
{
// 「FireMissile」スクリプトを有効にする。(ポイント)
fireMissile_B.GetComponent<FireMissile>().enabled = true;
fireMissile_C.GetComponent<FireMissile>().enabled = true;
// 5秒後に元の状態(攻撃力)に戻す。
// パワーアップ状態を何秒間にするかは自由!
Invoke("Normal", 5);
}
}
}
// プレーヤーの攻撃力を元に戻すメソッド
void Normal()
{
if (fireMissile_B && fireMissile_C)
{
// 「FireMissile」スクリプトを無効にする。(ポイント)
fireMissile_B.GetComponent<FireMissile>().enabled = false;
fireMissile_C.GetComponent<FireMissile>().enabled = false;
}
}
}


【2019版】Danmaku Ⅱ(基礎2/全38回)
他のコースを見る










攻撃力アップ
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PowerUPItem : Item // 「MonoBehaviour」を「Item」に変更する(これで「Itemクラスを承継」することができます。)
{
private GameObject fireMissile_B;
private GameObject fireMissile_C;
private void Start()
{
fireMissile_B = GameObject.Find("FireMissileB");
fireMissile_C = GameObject.Find("FireMissileC");
}
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Missile")
{
// (重要ポイント)ItemクラスのItemBaseメソッドを呼び出す。
base.ItemBase(other.gameObject);
if (fireMissile_B && fireMissile_C)
{
// 「FireMissile」スクリプトを有効にする。(ポイント)
fireMissile_B.GetComponent<FireMissile>().enabled = true;
fireMissile_C.GetComponent<FireMissile>().enabled = true;
// 5秒後に元の状態(攻撃力)に戻す。
// パワーアップ状態を何秒間にするかは自由!
Invoke("Normal", 5);
}
}
}
// プレーヤーの攻撃力を元に戻すメソッド
void Normal()
{
if (fireMissile_B && fireMissile_C)
{
// 「FireMissile」スクリプトを無効にする。(ポイント)
fireMissile_B.GetComponent<FireMissile>().enabled = false;
fireMissile_C.GetComponent<FireMissile>().enabled = false;
}
}
}


アイテムの作成④(攻撃力アップ)