~省略~
public class AoiController : MonoBehaviour, ICounterReceiver
{
~省略~
public void spawnAoi() {
// prefab からインスタンスを生成
Vector3 pos = posTarget.transform.position;
pos.z = 0;
pos.x += (UnityEngine.Random.value - 0.5f); // 若干出現地点を左右に分散させる
GameObject aoi = Instantiate(prefab, pos, Quaternion.identity);
~省略~
// 生み出した葵ちゃんに力を与える
aoiBody.AddForce(direction * prefabSpeed, ForceMode2D.Force);
aoiBody.AddTorque(torque * prefabTorque, ForceMode2D.Force);
// 生成時の負荷軽減のため、接触判定を0.2秒間保留する。
CapsuleCollider2D collider = aoi.GetComponent<CapsuleCollider2D>();
collider.enabled = false;
StartCoroutine(DelayCoroutineSeconds(0.1f * (gameCntl.GetCount() * 0.01f), () => {
collider.enabled = true;
}));
}
private IEnumerator DelayCoroutineSeconds(float interval, Action action)
{
yield return new WaitForSeconds
(interval
); action?.Invoke();
}
~省略~
}