アイテムの作成(ボスの攻撃を一定時間停止)



タイマーで敵の攻撃を停止する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyFireMissile : MonoBehaviour
{
public GameObject enemyMissilePrefab;
public float missileSpeed;
private int timeCount = 0;
// ★追加
public float stopTimer = 10;
void Update()
{
timeCount += 1;
// ★追加
// タイマーを進める
stopTimer -= Time.deltaTime;
// ★追加
// タイマーが0未満になったら「0」で止める。
if (stopTimer < 0)
{
stopTimer = 0;
}
// ★追加
print("攻撃開始まであと" + stopTimer + "秒");
// ★追加
// タイマーが0以下になったら敵が攻撃を開始する。
if (timeCount % 60 == 0 && stopTimer <= 0)
{
GameObject enemyMissile = Instantiate(enemyMissilePrefab, transform.position, Quaternion.identity);
Rigidbody enemyMissileRb = enemyMissile.GetComponent<Rigidbody>();
enemyMissileRb.AddForce(transform.forward * missileSpeed);
Destroy(enemyMissile, 3.0f);
}
}
// ★追加
// タイマーの時間を増加させるメソッド
public void AddStopTimer(float amount)
{
stopTimer += amount;
}
}

攻撃停止アイテム
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StopAttackItem : MonoBehaviour
{
public GameObject[] targets;
void Update()
{
// ★「EnemyFireMissile」プレハブに「EnemyFireMissile」のタグを付けてください。(ポイント)
targets = GameObject.FindGameObjectsWithTag("EnemyFireMissile");
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Missile")
{
Destroy(other.gameObject);
for (int i = 0; i < targets.Length; i++)
{
targets[i].GetComponent<EnemyFireMissile>().AddStopTimer(10.0f);
}
Destroy(gameObject);
}
}
}






タイマーで敵の攻撃を停止する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyFireMissile : MonoBehaviour
{
public GameObject enemyMissilePrefab;
public float missileSpeed;
private int timeCount = 0;
// ★追加
public float stopTimer = 10;
void Update()
{
timeCount += 1;
// ★追加
// タイマーを進める
stopTimer -= Time.deltaTime;
// ★追加
// タイマーが0未満になったら「0」で止める。
if (stopTimer < 0)
{
stopTimer = 0;
}
// ★追加
print("攻撃開始まであと" + stopTimer + "秒");
// ★追加
// タイマーが0以下になったら敵が攻撃を開始する。
if (timeCount % 60 == 0 && stopTimer <= 0)
{
GameObject enemyMissile = Instantiate(enemyMissilePrefab, transform.position, Quaternion.identity);
Rigidbody enemyMissileRb = enemyMissile.GetComponent<Rigidbody>();
enemyMissileRb.AddForce(transform.forward * missileSpeed);
Destroy(enemyMissile, 3.0f);
}
}
// ★追加
// タイマーの時間を増加させるメソッド
public void AddStopTimer(float amount)
{
stopTimer += amount;
}
}

攻撃停止アイテム
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StopAttackItem : MonoBehaviour
{
public GameObject[] targets;
void Update()
{
// ★「EnemyFireMissile」プレハブに「EnemyFireMissile」のタグを付けてください。(ポイント)
targets = GameObject.FindGameObjectsWithTag("EnemyFireMissile");
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Missile")
{
Destroy(other.gameObject);
for (int i = 0; i < targets.Length; i++)
{
targets[i].GetComponent<EnemyFireMissile>().AddStopTimer(10.0f);
}
Destroy(gameObject);
}
}
}



アイテムの作成(ボスの攻撃を一定時間停止)