(10秒後に敵が動き出す)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class EnemyStopItem : MonoBehaviour
{
public AudioClip getSound;
public GameObject effectPrefab;
private GameObject EnemyB;
private GameObject[] enemies;
// 削除
//public bool enabled= true;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
// 改良・重要
//Destroy(gameObject);
this.gameObject.SetActive(false);
AudioSource.PlayClipAtPoint(getSound, transform.position);
GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
Destroy(effect, 0.5f);
enemies = GameObject.FindGameObjectsWithTag("EnemyB");
foreach (GameObject e in enemies)
{
//e.GetComponent<NavMeshAgent>().enabled = false;
// (改良)スピードを0にする
e.GetComponent<NavMeshAgent>().speed = 0;
}
// (追加)
// 3秒後にスピードを戻す。
Invoke("ResetSpeed", 3);
}
}
// (追加)
void ResetSpeed()
{
enemies = GameObject.FindGameObjectsWithTag("EnemyB");
foreach (GameObject e in enemies)
{
// (改良)スピードを1に戻す
e.GetComponent<NavMeshAgent>().speed = 1;
}
}
}