(Unity)画面上の全ての敵を特定の場所に一気にワープさせる(foreachの活用)

(スクリプト)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LuckyCat : MonoBehaviour
{
    private GameObject[] enemies;

    private void OnTriggerEnter(Collider other)
    {
        if(other.gameObject.CompareTag("Player"))
        {
            enemies = GameObject.FindGameObjectsWithTag("Enemy");

            foreach(GameObject e in enemies)
            {
                e.transform.position = new Vector3(0, 0, 5);
            }
        }
    }
}

(実行結果)

  • 敵が一気にワープすれば成功